Use media url , store url, skin url same as CMS Page content in custom module

Posted: January 8, 2013 in Magento
Tags: , , , , , ,

Hello,

Magento Core, Admin Static Blocks, CMS Page, or Phtml edits are usually includes getting url path such images, javascript, base url, media and store url. There are different ways to retrieve mentioned URL paths depending on where section you’re editing.

For Eg: {{skin url=’images/sampleimage.jpg ‘}}, {{media url=’/sampleimage.jpg’}}, {{store url=’mypage.html’}}

We can also use the above ways in our custom modules Content/Textarea field values. I know one question arise in your mind that “How will it display in frontend?”.

I am here to show you how can we display its content in frontend. We will create One function in block file.



public function processHtml($content)
{

        /* @var $helper Mage_Cms_Helper_Data */
        $helper = Mage::helper('cms');
        $processor = $helper->getPageTemplateProcessor();
        $html = $processor->filter($content);
        return $html;
}


Lets say your textarea field name of your module is ‘content’ you can display content like:


<?php echo $object->getContent(); ?>

//Instead of above code, you need to use below code to display


<?php echo $this->processHtml($object->getContent());?>

I hope above content is useful to you. Thanks for reading my blog.

Thanks,
Bijal Bhavsar 🙂

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s