'Add php code to Static Block
I'm looking for a way to add php to a static block in Magento. I have tried numerous ways, but the editor changes
Solution 1:[1]
There is some quite limited short-tag support in static blocks, but you're probably better off calling a template file. You can do this inside your static block if you prefer:
{{block type="cms/block" block_id="your_block_identifier" template="your_path/template.phtml"}}
Then make a new template file and you can run your php stuff in there.
Solution 2:[2]
This is a working way and eliminating unnecessary code
{{block type="core/template" template="page/urfile.phtml"}}
Solution 3:[3]
You cant add php code directly on the static block. You can call the phtm file as pspahn stated. You can also add the magento widget to the static block which also runs php. On static block you can use the html code, also you can use magento api like skin url etc on static block
Solution 4:[4]
You cannot add PHP code into static blocks
but you can add a link to your phtml file into static block
- Create your sample.phtml file
- write your code in sample.phtml
Then add this file into the static file as
{{block type="core/template" template="catalog/category/sample.phtml"}}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | pspahn |
| Solution 2 | Bhargav Mehta |
| Solution 3 | pamincognito |
| Solution 4 | Smita Kagwade |
