0

How to display a top menu link with dropdown in the header of my site?

1 Answer 1

2

First Override template file from module to our theme,

magento2/app/design/frontend/Magento/{{themename}}}/Magento_Customer/templates/account/customer.phtml

Keep below code to customer.phtml file,

 <li class="customer-welcome">
        <span class="customer-name"
              role="link"
              tabindex="0"
              data-mage-init='{"dropdown":{}}'
              data-toggle="dropdown"
              data-trigger-keypress-button="true"
              data-bind="scope: 'customer'">
            <?php if($block->customerLoggedIn()): ?>
                <span data-bind="text: customer().fullname"></span>
            <?php else: ?>
                <span>Account</span>
            <?php endif; ?>
            <button type="button"
                    class="action switch"
                    tabindex="-1"
                    data-action="customer-menu-toggle">
                <span><?php /* @escapeNotVerified */ echo __('Change')?></span>
            </button>
        </span>
        <script type="text/x-magento-init">
        {
            "*": {
                "Magento_Ui/js/core/app": {
                    "components": {
                        "customer": {
                            "component": "Magento_Customer/js/view/customer"
                        }
                    }
                }
            }
        }
        </script>
        <?php if($block->getChildHtml()):?>
        <div class="customer-menu" data-target="dropdown">
            <?php echo $block->getChildHtml();?>
        </div>
        <?php endif; ?>
    </li>

After clear var folder, You have to dispaly dropdown menu for top links.

2
  • Where to add dropdown option? What does <?php echo $block->getChildHtml();?> indicates?
    – Nafsss
    Commented Aug 13, 2019 at 11:34
  • I know a very long time, i just try what you post, for me not working, my version 2.3.4, any help thanks. @Rakesh Jesadiya
    – zus
    Commented Dec 5, 2020 at 10:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.