How to create new page in magento site

How to create new page in magento site

July 11, 2026 · Illustrated author avatarBy Stefan Bogdanescu
How to create new page in magento site

Creating a New Page in Magento: A Comprehensive Guide

Introduction

Magento is a powerful e-commerce platform that allows you to create robust online stores. If you’re looking to add a new page to your Magento site with custom HTML and JavaScript, this guide will walk you through the process step-by-step.

Understanding Your Current Setup

You’ve already created a module named CompanyName_Helloworld. The configuration file (config.xml) is properly set up to define the module’s version and create a frontend router. This allows Magento to route requests for /Helloworld URLs to your new module’s controller.

The IndexController.php file defines an indexAction method that loads the layout and renders it. Currently, this will display just the header and footer of your site, as specified in your theme’s layouts.

Adding Custom Content: The Layout XML File

To add custom content between the header and footer, you need to create a new layout XML file under app/design/frontend/<your_package>/<your_theme>/layout. Let’s name this file helloworld.xml.

Here’s what the contents should look like:

<?xml version="1.0"?>
<layout version="1.0">
    <default>
        <reference name="content">
            <block type="core/text" name="my_custom_block">
                <action method="setText">
                    <text>Hello, World! My custom content goes here.</text>
                </action>
                <block type="core/html" template="html.phtml"/>
            </block>
        </reference>
    </default>
</layout>

In this example, we are adding a new block named my_custom_block inside the default layout’s content area. The setText action assigns the text within the <text> tags to be displayed in this block.

Creating the Custom Template File

Next, you need to create the PHTML file that will contain your custom HTML and JavaScript code. Create a new folder named ‘templates’ under your theme’s directory (app/design/frontend/<your_package>/<your_theme>). Within this ‘templates’ folder, create another folder named after your module (e.g., CompanyName_Helloworld).

Inside the CompanyName_Helloworld folder, create a file named html.phtml. This is where you will add your custom HTML and JavaScript code.

<div id="my-div">
    Here's my custom content with some <strong>formatting</strong>.
    <script type="text/javascript">
        // Your JavaScript code goes here.
    </script>
</div>

Linking the Layout XML to Your Module

To ensure that your new layout file is applied when using your module, you need to update your config.xml file. Add the following lines inside the <frontend> section:

<layout>
  <updates>
    <helloworld>
      <file>app/design/frontend/<your_package>/<your_theme>/layout/helloworld.xml</file>
    </helloworld>
  </updates>
</layout>

Replace <your_package> and <your_theme> with the actual names of your package and theme.

Testing Your New Page

With everything set up, you should now be able to access your new page at http://<your_domain>/index.php/Helloworld. You should see the header, your custom content within the <div id="my-div"> tags, and the footer of your site. The JavaScript code added inside the script tag will also execute.

Conclusion

Creating a new page in Magento involves creating a module, defining the layout structure, and adding custom HTML and JavaScript code. By following this guide, you should now be able to add new pages to your Magento site with ease.

Remember, if you’re looking for more advanced solutions or have any other questions about Magento development, feel free to check out our articles at Laravel Company. We provide a wealth of information on e-commerce development, including guides on Magento themes, extensions, and best practices.

Extensions Themes Configuration JavaScript

Our network