[英]How to call Magento block in phtml template?
我需要在頁腳中顯示更多鏈接。 我在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靜態塊內容。 問題是什么?
$this->getLayout()->createBlock('cms/block')->setBlockId('my_static_block_name')->toHtml()
引用是先前定義的塊,您希望塊在內部,例如:
<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') ?>
你可以調用一個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中使用塊。
如果你不想打擾XML,就像swapnesh的答案一樣,我只是讓它更清晰的那里的php noobs(像我一樣)
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('your_identifier')->toHtml() ?>
your_identifier是您在CMS> Blocks> Create New Block中創建塊時決定使用的代碼,第二行稱為“Identifier”
將您的引用名稱更改為頁腳
喜歡
<reference name="footer">
然后它會工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.