Magento - 将 phtml 文件添加到布局块
我正在尝试添加一些代码,这些代码将在产品页面上的产品价格正下方显示文本 - 此外,我尝试以“Magento”方式执行此操作,不仅将代码复制到 view.phtml 中,而且通过在块中创建,然后在布局文件中引用该块。
无论好坏,我都在尝试遵循本教程。
到目前为止,我已经创建了包含我想要显示的内容的 phtml 文件(sharethis.phtml) 在页面 xml 中创建了一个引用:
<block type="core/text_list" name="sharethis" as="sharethis"/>
就在这个块之后
<block type="core/text_list" name="left" as="left" translate="label">
<label>Left Column</label>
</block>
在catalog.xml 中引用了该引用,就在第一个默认标记之后:
<reference name="sharethis">
<block type="catalog/product_new" name="sharethis" template="catalog/product/view/sharethis.phtml"/>
</reference>
最后从 view.phtml 文件中调用了该块,如下所示
<?php echo $this->getChildHtml('sharethis') ?>
但它没有显示。有什么建议吗?
I am trying to add some code that will display text directly below the product's price on the product page - further, Im trying to do this the 'Magento' way by not just copying the code into view.phtml, but by creating at block, and then referencing that block in a layout file.
For better or worse, I am trying to follow this tutorial.
So far I have created the phtml file that contains what I want to display (sharethis.phtml)
Created a reference in page xml:
<block type="core/text_list" name="sharethis" as="sharethis"/>
just after this block
<block type="core/text_list" name="left" as="left" translate="label">
<label>Left Column</label>
</block>
Referenced that reference in catalog.xml, just after the first default tag:
<reference name="sharethis">
<block type="catalog/product_new" name="sharethis" template="catalog/product/view/sharethis.phtml"/>
</reference>
And finally called that block from the view.phtml file like so
<?php echo $this->getChildHtml('sharethis') ?>
But its not showing up. Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否想添加结构块?或者只是比价格低一个街区?因为它们是不同的。如果我理解您在catalog.xml(布局文件)中尝试执行的操作,请添加:
基本上要回显子块,该块必须是您所在块的子级。
此外,您的类型可能是错误的,请确保您正在使用正确的类型。
Are you trying to add a structural block? or just a block underneath the price? as they are different. If i understand what your trying to do in catalog.xml (layout file) add:
Basically to echo a child block the said block has to be a child of the block your in.
Also your type might be wrong, make sure you are using the correct type.
我不认为你可以有 2 个同名的块(这就是你将得到的,因为你声明了 2 个块“sharethis”)
I don't think you can have 2 blocks with the same name (here it's what you'll get, since you're declaring 2 blocks "sharethis")