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

时间:2023-01-24 11:05:48

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

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

and then i added following code page.xml file

然后我添加了以下代码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>

i called this one in footer.phtml as,

我在footer.phtml中称这个为,

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

but it does not display the CMS static block content. what is the issue?.

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

5 个解决方案

#1


12  

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') ?>

#2


15  

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

#3


7  

You can call a statick block like:

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

<?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.

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

#4


3  

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)

如果你不想打扰XML,就像swapnesh的答案一样,我只是让它更清晰的那里的php noobs(像我一样)

<?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"

your_identifier是您在CMS> Blocks> Create New Block中创建块时决定使用的代码,第二行称为“Identifier”

#5


0  

change your reference name to footer

将您的引用名称更改为页脚

like

喜欢

<reference name="footer">  

then it will work.

然后它会工作。

#1


12  

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') ?>

#2


15  

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

#3


7  

You can call a statick block like:

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

<?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.

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

#4


3  

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)

如果你不想打扰XML,就像swapnesh的答案一样,我只是让它更清晰的那里的php noobs(像我一样)

<?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"

your_identifier是您在CMS> Blocks> Create New Block中创建块时决定使用的代码,第二行称为“Identifier”

#5


0  

change your reference name to footer

将您的引用名称更改为页脚

like

喜欢

<reference name="footer">  

then it will work.

然后它会工作。