Displaying Wishlist Block in Header in Magento 1.x
If you’re looking to display your wishlist block in the header of your Magento 1.x site, you’ve come to the right place. In this post, we’ll guide you through the process step-by-step.
Understanding the Wishlist Configuration
Before making changes, it’s essential to understand how the wishlist is configured by default. In Magento 1.x, the wishlist is set up in the wishlist.xml file located under app/design/frontend/[your_package]/[your_theme]/layout/.
In this file, you’ll find the following configuration:
<wishlist>
<reference name="left">
<block type="wishlist/customer_sidebar" name="wishlist_sidebar" as="wishlist" template="wishlist/sidebar.phtml"/>
</reference>
</wishlist>
As you can see, by default, the wishlist is added to the left sidebar.
Moving Wishlist to the Header
Now let’s move the wishlist block to the header. To do this, we need to make a copy of your current theme in app/design/frontend/[your_package]/[your_theme]/.
Once you have the copied theme folder, navigate to the layout directory inside it and find or create a new file called local.xml. This is where we’ll add our custom layout updates.
Open local.xml and add the following code:
<layout version="1.0">
<default>
<reference name="header">
<block type="wishlist/customer_sidebar" name="wishlist_sidebar" as="wishlist" template="wishlist/sidebar.phtml"/>
</reference>
</default>
</layout>
Here’s what we’re doing:
- We create a new
defaultlayout handle. - Under this handle, we specify the header block (
header). - Inside the header block, we add our wishlist sidebar block using the same type and template as in the default configuration.
Clearing Cache
After making these changes, you need to clear your Magento cache for the updates to take effect. You can do this in several ways:
-
Manually: Navigate to
System > Configuration > Advanced > Systemin your admin panel and click “flush cache.” -
Using SSH: If you have SSH access to your server, you can run this command:
php bin/magento cache:clean
Conclusion
Displaying the wishlist block in the header is a straightforward process that involves creating a copy of your theme, editing the local.xml file, and clearing the cache.
Remember, working with Magento’s layout files requires careful attention to avoid breaking any existing functionality. Always make sure you have a backup before making significant changes.
For more advanced customizations like this, consider checking out our guide on Extending Magento’s Core Functionality.
Let us know if you have any other questions or need further assistance!