Render Template Blocks in Custom WYSIWYG

When developing admin models that have CMS capabilities, it’s likely that you’ll want to use Magento’s WYSIWYG editor in a similar manner to static blocks and CMS pages. By that I mean if you choose to embed a template file to run PHP scripts, you can do so using code similar to this:

{{block type=”core/template” template=”page/html/hello.phtml”}}

This is only possible if you render your content using a method in the CMS Helper called getBlockTemplateProcessor(). Like a fresh can of Ronseal it does exactly what it says on the tin and allows you to process template blocks in your content.

$processor = Mage::helper('cms')->getBlockTemplateProcessor();
$html = $processor->filter($this->getContentArea());

The result of using this is demonstrated below:

Differences using getBlockTemplateProcessor()
Differences using getBlockTemplateProcessor()

* Remember, don’t ever call your content areas ‘content’ or your WYSIWYG editor will blow up.

Hope this helps someone, thanks for reading!

  • It was exactly what I was looking for. It also works for custom attributes that you want to parse new blocks.
    In my case, I’ve created a new block type. If you do that, don’t forget to whitelist the block under System>Permissions>Blocks.

    • Kirsty Marks

      Hi Ricardo, Can I ask where you got the information to do this with custom attributes please as I am looking for this piece of code 🙂 Thankyou