Foundation 5 Navigation Dropdown Menu
Like foundation 5 for a number of treasons and modifying the template for Perch. As a relative newbie getting on great and the pageDepth explanation by Drew and the outline code by James Higginbotham helped get to a working navigation but...
To use the foundation menu each dropdown parent <a> is given an id="hover?" to identify parent and data block to display on hover.
Having got this far not sure if can create an incrementing id="variable" for each <a> with subitems or if even possible.
Or, if there is a simpler or easier option! Code so far as below. Maybe complicating this and hopefully, someone can suggest how or what better to use:-
<?php perch_pages_navigation(array(
'levels' => 2,
'template' => array('f-nav.html', 'f-nav-d.html'),
));
?>
f-nav.html
<perch:before>
<ul role="navigation" <perch:if id="pageDepth" match="eq" value="1">class="button-group"</perch:if>
<perch:if id="pageDepth" match="eq" value="2">class="dropdown"</perch:if>>
</perch:before>
<li
<perch:if exists="current_page">class="active selected"</perch:if>
<perch:if exists="subitems"> class="has-dropdown"</perch:if>
<perch:if exists="ancestor_page"> class="ancestor"</perch:if>>
<perch:if exists="subitems">
<a data-dropdown="hover1" data-options="is_hover:true; hover_timeout:500" class="button" href="<perch:pages id="pagePath" />" >
<perch:else />
<a class="button" href="<perch:pages id="pagePath" />" >
</perch:if>
<perch:pages id="pageNavText" /></a>
<perch:pages id="subitems" encode="false" />
</li>
<perch:after>
</ul>
</perch:after>
f-nav-d.html
<perch:before>
<ul id="hover1" class="f-dropdown mega" data-dropdown-content>
</perch:before>
<li>
<a href="<perch:pages id="pagePath" />"><perch:pages id="pageNavText" /></a>
<perch:pages id="subitems" encode="false" />
</li>
<perch:after>
</ul>
</perch:after>
You can't use
perch:content
tags in this context.Thought had maybe found a possible answer with
but nothing is appended in the output.
If can get working, can it be used with other elements eg
Again, you can't use
perch:content
tags in this context. Useperch:pages
tags.Thanks for that Drew; will try again as suggested.
That makes the difference, thanks but an anomaly, although incrementing at the top level (hover2, hover3) each sublevel <ul> is numbering the same (hover1). Html output:-
Reading the docs, if I understand, is that the numbering is reset each subitems group so showing as hover1 each time.
So, that is not going to work even if they were numbered sequentially.
Is there a way to repeat the top level incremented id for its subitems as that looks like what is needed for the dropdown to work?
Maybe complicating things too much as there might be a simpler way to implement dropdown menus.
Do the numbers need to be sequential, or just unique?
Think they only need to be unique and the parent id matches the subitems to identify the relevant dropdown for each top level item.
You could try using
id="_id"
Have tried substituting it for perch_item_index in a number of combinations but don't seem to be getting anywhere. Doesn't output any value.
Not sure exactly how it should be used to pass on a value. Is it used in conjunction with perch_item_index to generate unique values?
It should be a unique ID for each item.
Sorry, must be a friday thing, but just not getting it! Can't see how it is passed to its child <ul> to match up the subitems with their parent dropdown.
In the hard-coded version each data-dropdown has a unique id with the same id for its submenu <ul> but can't see how this can be accomplished when dynamically generated with perch_pages_navigation.
Does anything displayed with
<perch:showall />
look useful?When added to the right hand navigation it shows listing:-
and looks like there is an incremented item count for the 2 menu items.
Not sure how to add to the perch_pages_navigation block.
Wasn't thinking about last comment! Have added to template files for top navigation and this is what it output;-
Looks like top level menu items are incrementing ok but subitems all show as 1.
Which ID are you using? I'm not sure what I'm looking at.
Not sure what you mean by 'which ID are you using'. All did was add perch:showall to menu template and refreshed page to get listing. Looking at the source can see top level menu items are numbered hover1 to hover3 as expected but in each case where there is a dropdown each are being numbered hover1. Can't see how to re-use top level menu item id for its corresponding submenu.
Ok. I'm really not sure how to help as I don't understand the problem.
Can you distill it to a simpler example?
The best example is the static html hover menu code:-
Each menu with a dropdown has an <a> [data-dropdown="same-id"] and each block of dropdown items has a corresponding <ul> [id="same-id"] matching its parent item.
Hope that helps.
Maybe I'm over-complicating things trying this menu option and going to try something simpler in the meantime.
Use:
and:
That works perfectly, thanks Drew. Looking at the output from showall can see now these id's but as new to Perch didn't realise how they could be used but learning every day!
Thanks again for your help and patience.