I'm working on a bootstrap magento theme. My intentions are to have a dropdown menu for the
Here is a jsFiddle of the exact code I am using to produce the dropdown: jsfiddle/BqKNV/9/ (Must add .net as im <10 rep)
It works, on click it will produce a dropdown menu, although the menu appears on the left side of the header, whilst the button is on the right.
Here is a shot of before click: http://imgur.com/ErWYL8Y after click:http://imgur.com/lQKoQB1
My CSS is form bootstrap, with zero edits regarding dropdown menus.
$this->getChildHtml('topLinks')
<div class="header-container">
<div class="header">
<?php if ($this->getIsHomePage()):?>
<h1 class="logo"><strong><?php echo $this->getLogoAlt() ?></strong><a href="<?php echo $this->getUrl('') ?>" title="<?php echo $this->getLogoAlt() ?>" class="logo"><img src="<?php echo $this->getLogoSrc() ?>" alt="<?php echo $this->getLogoAlt() ?>" /></a></h1>
<?php else:?>
<a href="<?php echo $this->getUrl('') ?>" title="<?php echo $this->getLogoAlt() ?>" class="logo"><strong><?php echo $this->getLogoAlt() ?></strong><img src="<?php echo $this->getLogoSrc() ?>" alt="<?php echo $this->getLogoAlt() ?>" /></a>
<?php endif?>
<div class="menulinks">
<?php echo $this->getChildHtml('topMenu'); ?>
</div>
<div class="dropdown btn-group">
<a href="#" class="btn dropdown-toggle" data-toggle="dropdown">
Action
<span class="caret"></span>
</a>
<ul class="dropdown-menu">
<?php echo $this->getChildHtml('topLinks'); ?>
</ul>
</div>
<?php echo $this->getChildHtml('topContainer'); ?>
</div>
Best Answer
Add a
pull-right
class to<div class="dropdown btn-group">
.And an other thing. It's not OK to do this:
The html from
topLinks
is already wrapped in a<ul>
tag. This will result in<ul><ul><li></li>...</ul></ul>
....ugly.Instead try to change the links template to support different classes. (By the way...I think Magento should support this out of the box). And while you are at it, you can add
role="menu"
on the list as bootstrap best practices suggests.Here is how you can do that. The top links are rendered by
app/design/frontend/{interface}/{theme}/template/page/template/links.phtml
. For your theme you should make this template look as follows:The modifications I made here will not affect other sections rendered with this template.
Now you should tell Magento, that for top links you need an other class for the list and that the list acts as a menu.
In
app/design/frontend/{interface}/{theme}/layout/page.xml
there is this line that adds the top links block.Change it to: