Using PHP code on a CMS page (custom Block/module)

  • mangeto php code

If you have ever wanted to do some sort of PHP processing within a CMS page that you created, here is how you do it.
A limitation of this tutorials is form processing. That involves creating and/or extending and/or overriding a controller class (which I’ll save for another day).
This code will allow your code to accept arguments, making it handy for some sort of dynamic use!
These are the basic instructions to create any custom module as well!
Off we go:

1) 1. declare your module: app/etc/modules/MyCompany_All.xml

01.
02.
03.
04.<MyCompany_Custom>
05.true
06.local
07.
08.
09.

2. create module config: app/code/local/MyCompany/Custom/etc/config.xml

01.
02.
03.
04.
05.<mycompany_custom>
06.MyCompany_Custom_Block
07.
08.
09.
10.

3. Create your custom PHP code: app/code/local/MyCompany/Custom/Block/Test.php

01. 02.
03.class MyCompany_Custom_Block_Test extends Mage_Core_Block_Abstract
04.{
05.protected function _toHtml()
06.{
07.// put here your custom PHP code with output in $html;
08.// use arguments like $this->getMyParam1() , $this->getAnotherParam()
09.
10.return $html;
11.}
12.}

4. Use your custom PHP logic in CMS page/block:
1.{{block type=”mycompany_custom/test” my_param1=”value 1″ another_param=”value 2″}}cipro tab

Comments

Leave a Reply

Your email address will not be published.

17 − ten =

Security Code: