-
Notifications
You must be signed in to change notification settings - Fork 0
JSON: templates
This file contains an array of template objects.
The 'struct' part of the template object is either a string (for the bits surrounding the menu) or a keyed-array of similar strings within one of the lvl objects.
This string simply tells Flexwalker when to open and to close tags, using the id of a tag within tags.json. There is one reserved word, 'walker', which inserts the wp_nav_menu return when used in the top struct. Otherwise, the string is a nesting key, with '/' used to close the last opened tag. In pseudo code, this struct:
nav toggle toggleicon / / walker /
Turns into this code (using the id as the html tag):
<nav>
<toggle>
<toggleicon></toggleicon>
</toggle>
<!-- returned menu from Flexwalker_Walker -->
</nav>
Note that within the lvl objects, there are opening and close structs for 'lvl' and 'el'. See below for an explanation of how they work.
A template object looks like this:
{
"id": "yourid",
"depth": 1,
"struct": "nav toggle toggleicon / / walker /",
"lvl": []
}-
idis what you use to get this template when callingflexwalker() -
depthis the menu depth allowed and will override other walker depth arguments -
structdescribes the structure around the nav menu and its position within it -
lvlis an array containing 'lvl objects', described below
struct at this level allows you to put all menu-specific HTML here, which gives you more flexibility when coding your actual templates. If you need to go back to conventional menus instead of a deeply layered Bootstrap menu, for example, you can simply change which template you're using without having to modify the code in your theme header.
The lvl array tells Flexwalker what to build as it steps through your navigation menu via lvl objects. These objects have the following structure:
{
"check": {
"depth": 0,
"children": false,
"final": false
},
"struct": {
"lvlo": "",
"lvlc": "",
"open": "",
"close": "",
"item": "item",
"link": "a"
}
}-
checkis a set of rules for Flexwalker to check to see if it should apply thestructarray. Flexwalker will stop checking whendepthandchildrenboth evaluate to true:-
depthis compared against the current menu depth -
childrenis compared to whether this item has children -
finaltells Flexwalker whether to evaluatedepthas===(false) or>=(true). For example, ifdepthis1andfinalistrue, all menu depths of 1 and below will use this rule.
-
-
structis an array which contains 'tag' strings similar to those explained above:-
lvlois the tag structure when opening a new level containing this item's children -
lvlcmust balancelvlo(ie, all open tags fromlvlomust be closed) -
openare tags before this item and its children -
closemust balanceopen; will be after thelvlctags -
itemis the id of the tag used for the item, it does not need to be closed -
linkis the id of the tag used to link the item, it does not need to be closed
-
You may have as many lvl objects within a template as you like. Note again that Flexwalker stops once the check rules evaluate to true, so there's a practical limit.