Creating Your First PHTML Template in Minutes

๐Ÿ›’ B-Online Store

Premium Magento 2 Extensions & Services

Enhance your e-commerce store with high-quality extensions and expert Magento development services. Trusted by thousands of merchants worldwide!

๐Ÿ’ฌ WhatsApp Button โšก Flash Sale ๐Ÿท๏ธ Product Labels ๐ŸŒ Translation Suite
๐Ÿ”ฅ UP TO 71% OFF Limited Time!
โญ Thousands of Merchants ๐Ÿ›ก๏ธ Quality Guaranteed โšก Instant Download

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.