Creating Your First PHTML Template in Minutes

Magento uses the .phtml extension for template files, which are PHP files primarily used to output HTML. Magento’s PHTML format includes syntactic sugar for rendering logic like loops and conditionals, making it easier to integrate PHP logic in these templates.

Template File Location

Magento modules store presentational layer files in the view directory. Depending on whether you’re dealing with the frontend or the admin area, this directory contains either frontend or adminhtml subdirectories. For the frontend, create the following directory:

app/code/Itcforu/Kickstart/view/frontend/templates/

 

Create the Template File

Within the templates directory, create a new PHTML file named welcome.phtml:

app/code/Itcforu/Kickstart/view/frontend/templates/welcome.phtml

Add the following HTML content to the welcome.phtml file:

 

<h1>Hello world!</h1>

 

Displaying the Template

To render this template on the screen, you need to define where Magento should display it using layout XML, which will be covered next.