How to call Magento block in phtml template?

后端 未结 5 1116
温柔的废话
温柔的废话 2021-02-04 12:58

i need to display some more links in footer. i created those links in magento admin as static blocks (id = sample_links ).

and then i added following code page.xml file<

相关标签:
5条回答
  • 2021-02-04 13:12
    $this->getLayout()->createBlock('cms/block')->setBlockId('my_static_block_name')->toHtml() 
    
    0 讨论(0)
  • 2021-02-04 13:24

    You can call a statick block like:

    <?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('your_identifier')->toHtml() ?>
    

    And call a block like:

    <?php echo $this->getLayout()->createBlock('sidebar/left')->setTemplate('bannerslider/left.phtml')->tohtml(); ?>
    

    Visit magevn.com to see more usecase to use block in magento.

    0 讨论(0)
  • 2021-02-04 13:26

    The reference is the block previously defined that you want your block to be inside, e.g.:

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

    Then

    <?php echo $this->getChildHtml('sample_links') ?>
    
    0 讨论(0)
  • 2021-02-04 13:26

    If you don't want to bother with XML, same as swapnesh's answer, I'm just making it clearer for the php noobs out there (like me)

    <?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('your_identifier')->toHtml() ?>
    

    your_identifier is the code you decide to use when creating your block in CMS > Blocks > Create New Block, second line called "Identifier"

    0 讨论(0)
  • 2021-02-04 13:32

    change your reference name to footer

    like

    <reference name="footer">  
    

    then it will work.

    0 讨论(0)
提交回复
热议问题