Customizing Magento Customer Account Layout
Are you looking to give your Magento customer account pages a clean, streamlined look? One common request is to convert the layout from the default 2-column design into a single column page, while moving the customer navigation menu from the sidebar to the top of the content.
I’ll guide you through this process with easy-to-follow steps. Let’s dive right in!
Step 1: Change the Page Layout
First things first - we need to change the layout for all customer account pages from 2columns-left to 1column.
Update your app/design/frontend/<your_package>/<your_theme>/layout/customer_account.xml file as follows:
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<referenceBlock name="customer_account_navigation" template="Magento_Customer::account/navigation.phtml"/>
</page>
Replace <your_package> and <your_theme> with your current theme package and theme names.
Step 2: Move the Navigation Menu
Now, let’s move the customer navigation menu above the content area. To do this, we need to modify the default template file for the account page.
Open app/design/frontend/<your_package>/<your_theme>/template/customer/account/index.phtml and make the following changes:
Replace:
<div class="account-create">
<div class="page-title-wrapper">
<h1 class="page-title"><?= $block->escapeHtml(__('My Account')) ?></h1>
</div>
</div>
<div class="page-main-wrap">
<?= $block->getMessagesBlock()->toHtml() ?>
<?php if ($block->isLoggedIn()) :?>
<div id="maincontent" class="columns">
<!-- Customer navigation is placed here by default -->
</div>
<?php else: ?>
<div id="maincontent" class="columns">
<?= $block->getChildHtml('before') ?>
<div class="account-login">
<form action="<?= $block->escapeUrl($block->getPostActionUrl()) ?>" method="post"
id="login-form">
<!-- Login form fields go here -->
</form>
</div>
<?= $block->getChildHtml('after') ?>
</div>
<?php endif; ?>
</div>
With:
<div class="page-title-wrapper">
<h1 class="page-title"><?= $block->escapeHtml(__('My Account')) ?></h1>
</div>
<?= $block->getMessagesBlock()->toHtml() ?>
<div id="maincontent" class="columns">
<!-- Move the customer navigation above the login form -->
<?= $this->getChildHtml('customer_account_navigation') ?>
<?php if ($block->isLoggedIn()) :?>
<div class="account-login">
<form action="<?= $block->escapeUrl($block->getPostActionUrl()) ?>" method="post"
id="login-form">
<!-- Login form fields go here -->
</form>
</div>
<?php else: ?>
<div class="account-create">
<form action="<?= $block->escapeUrl($block->getCreatePostUrl()) ?>" method="post" id="form-validate">
<!-- Registration form fields go here -->
</form>
</div>
<?php endif; ?>
</div>
<?= $block->getChildHtml('after') ?>
Step 3: Save and Clear Cache
Save your changes, then clear the Magento cache. You can do this by running:
php bin/magento cache:clean
Or if you have maintenance mode enabled:
php bin/magento cache:flush
Visit your customer account page, and you should now see a clean, single-column layout with the navigation menu at the top.
Conclusion
With these steps, you’ve successfully customized the Magento customer account page to use a single column layout. You’ve also moved the customer navigation menu above the login/registration forms for a more intuitive user experience.
Remember, always make sure to test your changes thoroughly on all devices and browsers before deploying them live. And don’t forget to backup your files before making any modifications!
If you’re looking for professional Magento development services or want to learn more about customizing your store’s layout and navigation, feel free to reach out to the expert team at Laravel Company.
Happy coding!