Magento-将phtml文件添加到布局块 [英] Magento - Add phtml file to layout block
问题描述
我正在尝试添加一些代码,这些代码将在产品页面上直接在产品价格下方显示文本-进一步,我试图通过"Magento"方式实现此目的,不仅将代码复制到view.phtml中,还通过创建at块,然后在布局文件中引用该块.
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.
到目前为止,我已经创建了包含要显示的内容的phtml文件(sharethis.phtml) 在页面xml中创建了一个引用:
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"/>
紧挨着这个方块
<block type="core/text_list" name="left" as="left" translate="label">
<label>Left Column</label>
</block>
在第一个默认标记之后引用了catalog.xml中的引用:
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>
最后像这样从view.phtml文件中调用该块
And finally called that block from the view.phtml file like so
<?php echo $this->getChildHtml('sharethis') ?>
但是它没有出现.有什么建议吗?
But its not showing up. Any suggestions?
推荐答案
您是否要添加结构块?还是价格底下的一个街区?因为它们是不同的.如果我了解您要在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:
<catalog_product_view>
...
<reference name="content">
<block type="catalog/product_view" name="product.info" template="catalog/product/view.phtml">
<!--- ADD THIS -->
<block type="catalog/product_new" name="sharethis" template="catalog/product/view/sharethis.phtml"/>
<!-- END ADD -->
...
</block>
...
</reference>
...
</catalog_product_view>
基本上要回显一个子块,该块必须是您所在块的子块.
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.
这篇关于Magento-将phtml文件添加到布局块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!