1。最常见的一种方式:在layout文件中配置,然后在.phtml模板文件中输出。
2 |
< REFERENCE name = "content" > |
3 |
< BLOCK name = "cms_page" type = "cms/page" /> |
7 |
< BLOCK name = "home.catalog.product.new" type = "catalog/product_new" after = "default_home_page" template = "catalog/product/new.phtml" alias = "product_homepage_new" ></ BLOCK > |
2 |
echo $this ->getLayout()->getBlock( 'home.catalog.product.new' )->toHtml(); |
这种方式是Magento中推荐的标准方法。另外,也可以在后台 [Admin]->[CMS]->[Manage Pages]->[Home]->[Custome Design]->[Layout Update XML]中配置block xml。
2。不用在layout文件中配置,直接用PHP代码来创建block,并输出。
01 |
$layout = $this ->getLayout(); |
02 |
$type = 'catalog/product_new' ; |
04 |
'type' => 'catalog/product_new' , |
05 |
'name' => 'home.catalog.product.new' , |
06 |
'alias' => 'product_homepage_new' , |
07 |
'template' => 'catalog/product/new.phtml' |
09 |
$block = $layout ->createBlock( $type , null, $attributes ); |
10 |
echo $block ->toHtml(); |
3。出现在Magento邮件模板中,或自定义内容中的Magento标签:
1 |
{{block type="catalog/product_new" name="home.catalog.product.new" alias="product_homepage_new" template="catalog/product/new.phtml"}} |
Magento Block相关资料:Magento调用静态块(static block)
所有评论(0)