如何在phtml模板中调用Magento块?

时间:2012-05-18 06:17:53

标签: php magento content-management-system block

我需要在页脚中显示更多链接。我在magento admin中创建了这些链接作为静态块(id = sample_links)。

然后我添加了以下代码page.xml文件

<reference name="foot_lnk">  
<block type="cms/block" name="sample_block" before="-">
      <action method="setBlockId"><block_id>sample_links</block_id></action>
    </block>
</reference>

我在footer.phtml中称之为,

<?php echo $this->getChildHtml('foot_lnk') ?>

但它不显示CMS静态块内容。问题是什么?。

5 个答案:

答案 0 :(得分:20)

$this->getLayout()->createBlock('cms/block')->setBlockId('my_static_block_name')->toHtml() 

答案 1 :(得分:14)

引用是先前定义的块,您希望块在内部,例如:

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

然后

<?php echo $this->getChildHtml('sample_links') ?>

答案 2 :(得分:7)

你可以调用一个statick块,如:

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

并调用一个块:

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

访问magevn.com以查看更多用例以在magento中使用块。

答案 3 :(得分:3)

如果您不想打扰XML,与swapnesh的答案一样,我只是让那些php noob更清楚(像我一样)

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

your_identifier是您在CMS中创建块时决定使用的代码&gt;块&gt;创建新块,第二行称为&#34;标识符&#34;

答案 4 :(得分:0)

将您的参考名称更改为页脚

<reference name="footer">  

然后它会起作用。

相关问题