Rearranging Magento Login/Log Out Links Using local.xml
If you’re looking to rearrange your top links using local.xml, specifically the login/log out links in Magento, you can achieve this without having to remove them and re-add them manually with modified position tags.
Understanding the Default Configuration
By default, Magento sets both the “Log In” and “Log Out” links at position 100 in the customer.xml file:
<customer_logged_in>
<reference name="top.links">
<action method="addLink" translate="label title" module="customer">
...
<position>100</position>
</action>
</reference>
</customer_logged_in>
<customer_logged_out>
<reference name="top.links">
<action method="addLink" translate="label title" module="customer">
...
<position>100</position>
</action>
</reference>
</customer_logged_out>
Using local.xml to Modify the Position
To change the position directly, you can use the local.xml file located in your Magento theme directory. Here’s how to do it:
In your app/design/frontend/<your_package>/<your_theme>/layout/local.xml file (create this file if it doesn’t exist), add the following code within the <layout> tags:
<customer_logged_in>
<reference name="top.links">
<action method="setAttribute" attribute="position">1</action> <!-- for Log Out -->
</reference>
</customer_logged_in>
<customer_logged_out>
<reference name="top.links">
<action method="setAttribute" attribute="position">2</action> <!-- for Log In -->
</reference>
</customer_logged_out>
In this configuration, I’ve used the setAttribute action method to directly set the position of both “Log Out” and “Log In” links. The 1 value is applied to the “Log Out” link when a customer is logged in, while the 2 value is applied to the “Log In” link when a customer isn’t logged in.
Explanation of the Method
The setAttribute method works by allowing you to directly set an attribute for an element. In this case, we’re setting the position attribute of the links within the top.links block.
By using local.xml, you can override default configurations without having to modify core files or create a new moduleâwhich is a best practice in Magento development.
Conclusion
Rearranging top links, including login/log out links, using local.xml provides a clean and efficient way of modifying the layout. It’s perfect for small customizations like this as it doesn’t require extensive coding or file modifications.
Remember to clear your cache after making changes to see the updates reflected in your frontend.
For more advanced Magento layout modification techniques, consider following the tutorials on Laravel Company.