Calling the phtml file from cms page – Magento 1x

This tutorial is about calling the phtml template in cms page. This tutorial will be straight forward. In summary, We will create a new page in admin panel and custom phtml file in the backend. So, before we move forward this tutorial is applied only on the Magento 1x.

Step 1:

Login into the admin panel and hover to the cms nav and click on the pages

Step 2:

After that you will see the cms manage page, click on the add new page button and enter

Page Title: Enter the page name. For example : Homepage 1

URL Key: Enter the url key. For example : homepage_one. The identifier is one which will be used to call in the phtml file.

Store View: Select the appropriate store to display that page.

Status: Select enabled

Content: Enter the content
In the content part we enter this code to call the phtml file.

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

If you write to visit the page, i.e. [http://domainname.com/homepage_one] the page will display empty because we have not created any file on the backend.

Step 3:

Go to the template folder (app > design > frontend > themename > default > template > page). You can use another folder if you want to for this tutorial I am using magento default page folder.

Create a file named as custom-template.phtml and write “hello world” for test purpose to check if the page is called successfully.
After you have saved the file, please don’t forget to clear the cache.

Additional Point:

As well as we can pass the category id or product id and use into the phtml file. Have a look at the code where the category id has been passed and called in the phtml file

 {{block type="core/template" template="page/custom-template.phtml" category_id="23"}} 
 $category_id = $this->getData('category_id'); 




Leave a Reply

Your email address will not be published. Required fields are marked *