【问题标题】:Magento Block TagMagento 块标签
【发布时间】:2013-04-22 17:15:08
【问题描述】:

请解释一下 Magento 区块标签的所有属性

<block type="catalog/product_featured" name="product_featured" 
     as="product_featured" 
     template="catalog/product/featured.phtml"></block>
<block type="catalog/product_featured" name="product_featured"              template="catalog/product/featured.phtml">
<action method="setLimit"><limit>2</limit></action>
 </block>

还有为什么我们需要两倍的block标签

【问题讨论】:

  • 那里有文档和教程可以教您 Magento 块的基础知识。这里不适合要求解释 Magento 的基本原理(除非您自己用尽了资源)。

标签: magento


【解决方案1】:

type = PHP 文件,模板将查找方法。这里是 Mage_Catalog_Block_Product_Featured.php

name = 块的名称。它在页面中应该是唯一的。

as = 别名。较小的名称形式。它在其父块中应该是唯一的。

template = 此块附加到的模板文件(视图)。您可以使用 $this.. 来调用 this 内部块类型的方法。 $this->getName()

nameas 示例:

<reference name="left">
    <block type="block/type1" name="first_block" template="template1.phtml">
       <block type="abc/abc" name="abc" as="common" template="abc.phtml"/> 
    </block>
    <block type="block/type2" name="second_block" template="template2.phtml">
       <block type="xyz/xyz" name="xyz" as="common" template="xyz.phtml"/>            
    </block>
</reference>

因此,您现在可以从first_block 调用块名称abc 和从second_block 调用xyz 作为$this-&gt;getChildHtml('common');,但是看到调用的块将根据它们的调用父级而有所不同。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2023-03-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-02-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多