Magento – Call Custom Template in CMS Page

cmsstatic-block

I would like to know how I can display custom code in a CMS page. When using static blocks I can use the following code:

{{block type="cms/block" block_id="customcode"}}

I guess it has to be something like this:

{{block type="core/template" template="custom/code.phtml"}}

Does it work like that? Where do I put the file custom/code.phtml?

Best Answer

Let me give you an example, if you want to define a homepage for your website, all you'll have to do is create a CMS page called "home" (original right?) and add {{block type="core/template" template="page/html/home.phtml"}} to its content.
Then go to System > Configuration >General > Web > Default Page and there, select your freshly created home page, hit save.

It won't work, because that template (.phtml) file doesn't exist yet.
Go to your template folder (in your theme if you have one) and under /template/page/html create a file called home.phtml

In that file just wite <?php echo 'Hello world!' ?>. Refresh your website and you should see the message on the Homepage.

Related Topic