php - magento phtml content does not show in product page view.phtml -
i creating custom block inside product page view.phtml
. block created because can see block when turn on path hint. using plain html content template below:
<div> new block </div>
but if change template phtml content, returns message calling non-object function. below:
template
<?php $_helper = $this->helper('catalog/output'); ?> <?php $_product = $this->getproduct(); ?> <?php $productname = $_helper->productattribute($_product, $_product->getname(), 'name'); ?> <?php $producturl = $_helper->productattribute($_product, $_product->getproducturl(), 'product_url'); ?> <?php $productimage = $_product->getimageurl() ?> <div class="socialshare clearfix"> <ul> <li><a class="fa fa-facebook" href="javascript:popwin('https://www.facebook.com/sharer/sharer.php?u=<?php echo urlencode($producturl); ?>&t=<?php echo urlencode($productname); ?>', 'facebook', 'width=640,height=480,left=0,top=0,location=no,status=yes,scrollbars=yes,resizable=yes');" title="<?php echo $this->__('share it') ?>"></a></li> </ul> </div>
error message
fatal error: call member function getname() on non-object in /home/onebig/public_html/app/design/frontend/ma_hitstore/default/template/catalog/product/view/socialshare.phtml on line 3
catalog.xml have following codes
<catalog_product_view translate="label"> <reference name="content"> <block type="catalog/product_view" name="product.info" template="catalog/product/view.phtml"> <block type="core/template" name="product.info.socialshare" template="catalog/product/view/socialshare.phtml"/> </reference> </catalog_product_view>
view.phtml call block
<?php echo $this->getchildhtml('product.info.socialshare'); ?>
i tested if paste template content directly in view.phtml , works. guess if create custom block have redefine theses php variable $productname
, $producturl
, $productimage
somewhere? sorry new this. knowledge appreciated.
this issue child block has type core/template
. when call getproduct
on core template going return null.
if update catalog/product_view
$this->getproduct()
return product.
alternatively, can current product template fetching registry:
$_product = mage::registry('current_product');
Comments
Post a Comment