Magento - Add phtml file to layout block
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>
开发者_StackOverflow中文版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?
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.
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")
精彩评论