Displaying Layered Navigation in Static Blocks on Magento 1.8.1
In Magento 1.8.1, you can display layered navigation (similar to the category left navigation) within a static block without modifying local.xml. This is particularly useful when you want to convert parent categories into CMS pages that show the layered navigation of their sub-categories.
The Layered Navigation Template
Magento already provides a template called catalog/navigation/left.phtml which contains the logic for displaying layered navigation. Our goal is to call this template within a static block without modifying the XML layout file.
Step 1: Create a New Static Block
First, create a new static block in your Magento admin panel under Content > Widgets > Add New Block. Name it something like “Layered Navigation for CMS Pages”.
Step 2: Displaying the Layered Navigation
Within this new block, you can use the following code to call the layered navigation template:
{{block type="catalog/navigation" as="leftNav" template="catalog/navigation/left.phtml"}}
Here’s a breakdown of what we’re doing:
type="catalog/navigation"refers to the block type that handles the layered navigation.as="leftNav"gives this block a unique identifier within your template (optional, but good practice).template="catalog/navigation/left.phtml"specifies the template file to use.
Step 3: Using the Layered Navigation Block in Your CMS
Now, when editing your CMS page or any other content where you want to display this layer navigation, simply include the following:
{{block type="" name="leftNav"}}
Make sure the name attribute matches the identifier given with as (in our case, “leftNav”).
Step 4: Converting Categories into CMS Pages
To convert parent categories into CMS pages displaying their sub-categories’ layered navigation:
- Create a new CMS page for each category you want to transform.
- In the content area of this new page, include the layered navigation block as shown above.
- Redirect or link the original category view to this new CMS page.
Conclusion
By following these steps, you can display layered navigation within static blocks on Magento 1.8.1 without modifying your local.xml file. This allows for more flexible content management and improves the user experience by providing targeted navigation options in your CMS pages.
Remember to test your implementation thoroughly after making changes to ensure everything functions as expected with your specific theme and customizations.
For further guidance on Magento development, consider browsing our Magento tutorial series at Laravel Company.