Magento static pages menu

Magento static pages menu

July 8, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento static pages menu

Creating a Dynamic Menu for Enabled Static Pages in Magento

As an experienced e-commerce developer, I often receive requests from clients looking to create dynamic menus that display only active static pages within their Magento stores. This requires a solid understanding of the CMS and navigation system.

Understanding Magento’s Static Content Management System

The first step is to understand how Magento handles static content. Magento 2 provides a robust CMS that allows you to manage your store’s content through the admin panel. To create a new page, navigate to Content > Pages in your admin dashboard.

Here, you can add a title, URL key, and content for each page. The most important field is the “Enable” dropdown, which determines whether the page appears on your site. Only pages set to “Enabled” will be visible to customers.

Accessing the CMS Data Programmatically

To create a dynamic menu, we need to access this data programmatically and filter it based on the “Enable” status. Magento provides several ways to do this:

  1. Use the Magento 2 Object Manager: This is the most direct method but should be used sparingly due to performance implications. You can inject the Magento\Cms\Model\ResourceModel\Page\CollectionFactory into your controller or model and fetch the enabled pages.

    $pageCollection = $this->_pageCollectionFactory->create();
    $enabledPages = $pageCollection->addFieldToFilter('is_active', 1)->load();
    
  2. Use Magento’s built-in CMS page models: The Magento\Cms\Model\Page model provides a more stable and efficient way of fetching pages.

    $pages = \Magento\Framework\App\ObjectManager::getInstance()->create('Magento\Cms\Model\Page')->getCollection();
    $enabledPages = $pages->addFieldToFilter('is_active', 1);
    

Building Your Dynamic Menu

Once you have fetched the enabled pages, you can iterate through them and build your menu in whatever format you need.

$menuItems = '';
foreach ($enabledPages as $page) {
    if (!empty($menuItems)) {
        $menuItems .= ' | ';
    }
    $menuItems .= $page->getTitle();
}

This will give you a string containing the titles of your enabled pages separated by ” | ”. You can then display this string in your template using:

<?= $block->getMenuItems() ?>

Conclusion

Creating a dynamic menu for active static pages in Magento is a straightforward process that involves understanding Magento’s CMS, fetching data programmatically, and iterating through the results to build your menu.

Remember, performance is key when dealing with large numbers of pages. Always consider using pagination or loading only necessary data as your store grows.

For more advanced techniques on menu management in Magento, I recommend checking out our comprehensive guide at Laravel Company’s Magento Development Resources. This resource covers everything from setup to optimization and includes best practices for navigation management.

Magento 2 Performance Admin Deployment

Our network