How to display a top menu link with dropdown in the header of my site?
1 Answer
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.