Monday, January 18, 2010

Display CMS Blocks on product description (for Mattse)

Problem: add static block to product description

possible solution

You can add a new method to the product model.
function getDescription(){
$processor = Mage::getModel('core/email_template_filter');
$html = $processor->filter($this->getData('description'));
return $html;
}

In this way you can use the same {{block}} and {{skin}} sections just like the static blocks and pages and e-mail templates.

11 comments:

  1. Where do I find the product model? Where do I add this code? I would really lie to have static blocks inside of Product descriptions.

    ReplyDelete
  2. You will find the product model in app/code/core/Mage/Catalog/Model/Product.php

    But don't edit the core. Here is a way to override your model without editing the code: http://magedev.com/2009/06/03/magento-overriding-model-block-or-helper/

    ReplyDelete
    Replies
    1. which is the line to adding this? plese

      Delete
    2. Follow the tutorial for extending the product model. The code needs to go to the model you create to replace the product mode.

      Delete
  3. thaaaaaaaaaaaaaaaaaaaaaaank youuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu

    You saved my life!

    ReplyDelete
  4. hi tzyganu,

    nice function, can i get this to work in the short description as well? That way my static blocks can appear 'above the fold'?

    ReplyDelete
  5. Hello Adza...it should work for the short descrioption also. Just add the method
    function getShortDescription(){
    $processor = Mage::getModel('core/email_template_filter');
    $html = $processor->filter($this->getData('short_description'));
    return $html;
    }

    ReplyDelete
  6. Hi ,

    Is there a way to do it like wordpress . like just paste the short code right inside the product discription tab and the cms static block starts to show

    Many Thanks

    ReplyDelete
    Replies
    1. By default is not possible. But adding a new method like I described makes it possible.

      And please don't use the "W" word in here :)

      Delete
    2. Many Thanks for the technical Update . Will surely Try the same on my Wordpress Projects

      Delete