call cms/phtml from controller

call cms/phtml from controller

August 23, 2026 · Illustrated author avatarBy Stefan Bogdanescu
call cms/phtml from controller

Displaying CMS Page Content from Controller in Magento

If you’ve created a homepage using CMS by calling a PHTML file and want to display that same CMS page on your new website’s home page (index controller), you’re in the right place. Let’s walk through this step-by-step.

Calling PHTML File Directly from Controller

One approach is to directly call the PHTML file from your index controller action. Here’s how you can do it:

public function execute() {
    $this->loadLayout();
    $block = $this->getLayout()
        ->createBlock('core/template')
        ->setTemplate('path/to/your/file.phtml');

    $this->_addContent($block);
    $this->renderLayout();
}

Replace 'path/to/your/file.phtml' with the actual path to your PHTML file.

Calling CMS Page from Controller

Alternatively, you can call the CMS page itself from the controller. This is usually a cleaner approach:

public function execute() {
    $pageId = 1; // Set this to the ID of your CMS page
    $this->loadLayout();
    $cmsBlock = $this->getLayout()->createBlock('cms/block')
        ->setBlockId($pageId);

    $this->_addContent($cmsBlock);
    $this->renderLayout();
}

Removing Default Layout and Loading Image in PHTML

You mentioned you’re able to load the PHTML file but images aren’t loading. This is likely due to relative vs absolute path issues.

In your index.php or whatever layout file you’re loading, ensure that any <img> tags have absolute paths for their sources. Relative paths won’t work when called from a controller because the context changes.

Regarding the unwanted content showing up on the left and top, it sounds like you may be loading two different layouts. Ensure your index controller action is only calling one layout at a time using setLayout():

$this->loadLayout('your_layout_here');

Conclusion: Displaying CMS Content Cleanly

To display your CMS content cleanly from the controller in Magento, it’s best to call the CMS page directly rather than loading the PHTML file manually. This ensures you’re working with the built-in CMS functionality.

Remember:

  • Use absolute paths for images and assets.
  • Ensure you’re only setting one layout from the controller action.
  • Check your template XML files to ensure they don’t have any unwanted content included by default.

For a deeper dive into Magento’s layout system and best practices, I recommend checking out LaravelCompany’s guide on Magento Layouts. They provide a comprehensive overview of how layouts work in Magento.

Indexing Themes Errors

Our network