【发布时间】:2011-05-21 16:04:46
【问题描述】:
我昨天问了这个问题Static block on home page in Magento,它回答了我关于将 cms/block 连接到现有块(在该示例中为内容)的问题。
但现在我想知道如何创建自己的块。
我的 .phtml 模板中有这个:
<?php echo $this->getChildHtml('home_flash') ?>
这在我的 cms.xml 文件中
<reference name="home_flash">
<block type="cms/block" name="home-page-flash" before="content">
<action method="setBlockId"><block_id>home-page-flash</block_id></action>
</block>
</reference>
但这不起作用。
我还尝试在 page.xml 文件中创建自己的块类型(通过复制面包屑声明):
<block type="page/html_home_block" name="home_block" as="home_block" template="page/template/home_block.phtml"/>
该文件存在但未呈现。
但是当我像这样引用块时:
<block type="page/html_breadcrumbs" name="home_block" as="home_block" template="page/template/home_block.phtml"/>
它呈现了我的主块模板,但原始 cms/块没有附加到它。
希望所有不同的案例都能显示正在发生的事情并突出我的知识差距足以让别人回答,我是否必须在某处“注册”我的新“home_block”类型?
【问题讨论】:
-
不是 100% 清楚您要完成的工作,这使得理解问题变得困难。你能解释一下你想要达到的最终结果是什么,以及更具体的事情吗? (即“我的 .phtml 模板”:哪个 phtml 模板?)
-
@Alan Storm,感谢您的评论,我知道这个问题很长,我试图在最后用一行问题来总结! @clockworkgeek 回答了我的问题,结果我错过了关于 Magento 的 MVC 位的要点!
标签: php xml layout magento block