0

I want to add "children" to a given layout (custom-) block.

In my layout-xml:

<block type="core/text_list" name="custom_html_blocks_body_end" as="custom_html_blocks_body_end">
    ...
    <block type="page/html" name="custom_svg_icons" as="custom_svg-icons" template="my_templates/custom_svg-icons.phtml" />
    ...
</block>

The block i want to add childs programmatically is custom_svg_icons.

In custom_svg-icons.phtml:

<?php $this->getChildHtml(); ?>

And in my script to set the children:

$objSVG = $this->getLayout()->createBlock('page/html')->setTemplate('my_templates/svg_image.phtml')->setData(array('imageName'=>'svg-image-demo'));
$objSVGBlock = $this->getLayout()->getBlock('custom_svg-icons')->append($objSVG);

I get no Error, but nothing happens. There is no child.

  • Does your custom_svg-icons.phtml file called? – Akhilesh Patel Oct 11 '15 at 14:35
  • Yes. In this file is pure HTML too and rendered correctly to Output. – SFrey Oct 11 '15 at 15:12
  • You should do echo $this->getChildHtml() I think? – Milan Simek Oct 13 '15 at 3:17
  • I have tried with getChild() and getChildHtml() – SFrey Oct 13 '15 at 6:12
1

Not sure if that work but try

$objSVG = $this->getLayout()->createBlock('page/html')->setTemplate('my_templates/svg_image.phtml')->setData(array('imageName'=>'svg-image-demo'));

$objSVGBlock = $this->getLayout()->getBlock('custom_svg-icons');

$objSVGBlock->setChild('svg_image',$objSVG);

Or might be you will need to call toHtml after set the child.

$objSVGBlock->toHtml();
  • Thanks for the tip. But this not work. I can print the objSVG with ->toHtml directly... But not als Child from custom_svg-icons – SFrey Oct 11 '15 at 18:51
1

getBlock() needs the block name as a parameter, and that's custom_svg_icons in your case, not custom_svg-icons

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.