0

I am trying to show an attribute(Text area) in product page. My phtml file to call the attribute is description.phtml :

    <?php $_description = $this->getProduct()->getDescription(); ?>
<?php if ($_description): ?>
    <h2><?php echo $this->__('Details') ?></h2>
    <div class="std">
        <?php echo $this->helper('catalog/output')->productAttribute($this->getProduct(), $_description, 'description') ?>
    </div>
<?php endif; ?>

And I create a static block with this code:

<div id="tab1" class="tab active">
  <p> {{block type="core/template" template="page/description.phtml"}<p>  
</div>

Then I called my static block in view.phtml like this:

<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('product_details_tab')->toHtml() ?>

where the identifier of the static block is product_details_tab.

Instead of displaying the value given in the attribute field, It is displaying error like:

Fatal error: Call to a member function getDescription() on null.

Help me to resolve this. Where have I went wrong?

1

You need to replace from $this->getProduct() to Mage::registry('current_product')

For exp :

 <?php $_description = Mage::registry('current_product')->getDescription(); ?>
<?php if ($_description): ?>
    <h2><?php echo $this->__('Details') ?></h2>
    <div class="std">
        <?php echo $this->helper('catalog/output')->productAttribute(Mage::registry('current_product'), $_description, 'description') ?>
    </div>
<?php endif; ?>
1

You need to change the block type, So replace

<div id="tab1" class="tab active">
  <p> {{block type="core/template" template="page/description.phtml"}<p>  
</div>

with

<div id="tab1" class="tab active">
  <p> {{block type="catalog/product" template="page/description.phtml"}<p>  
</div>

Now your page will find the product blog to get the product.

Hope this will help you

  • Thank you for your guidance. I have upvoted your answer. – Ramya May 17 '16 at 8:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.