Frage

Synopsis

  • What is the difference between getChildHtml and getBlockHtml?
  • How can I get the cms/block title in the template?

I have essentially replaced the footer with my own footer and set my own <?= $this->getChildHtml('...') ?> This didn't work until I used: <?= $this->getBlockHtml('...') ?>.

Layout XML:

<layout>
    <default>
        <block type="core/template" name="custom_footer" as="footer" template="page/html/footer.phtml">
            <block type="cms/block" name="child_1">
                <action method="setBlockId"><block_id>footer_child_1</block_id></action>
            </block>
         </block>
    </layout>
</default>

Template (doesn't work):

<footer>
    <div class="row">
        <div class="col-sp4"><?= $this->getChildHtml('child_1') ?></div>
    </div>
</footer>

Template (Works):

<footer>
    <div class="row">
        <div class="col-sp4"><?= $this->getBlockHtml('child_1') ?></div>
    </div>
</footer>

Solution:

First of all I had to override the footer inside my local.xml by:

<default>
    <block type="core/template" template="page/html/custom_footer.phtml" name ="custom_footer" as "footer" />
</default>

The I had to add my children (in order for getChildHtml() to work):

<reference name="footer">
    <block type="cms/block" name="child_1">
         <action method="setBlockId"><block_id>footer_child_1</block_id></action>
    </block>
</reference>

Keine korrekte Lösung

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit magento.stackexchange
scroll top