Calling Methods from a Magento Static Block

I recently had to develop a bespoke CMS within magento.

One of the requirements was that the system should be very easy to customise, and should use the existing Pages and Static blocks functionality within magento.

I wanted the ability to call a block that I had created from with a static block. Magento allows you to do this using the code below {{block type=‘companyname/path_to_block’ name=‘custom.block’ template=‘path/to/template/file.phtml’}}

The issue that I came across if you need to call a method on the block before it is rendered. If I was calling the block using XML I could use the action tag, but that is not avalible here.

However, it is possible to call certain methods using the code above. The magento parser takes each of the pair values and calls a set method on them, so for example template=‘path…’ actually calls the setTemplate method on your block.

This means that you can create a set method and trigger it from with in the static block like so

{{block type=‘companyname/path_to_block’ name=‘custom.block’ template=‘path/to/template/file.phtml’ methodName=“3”}}