Skip to content

JSON: templates

rogerlos edited this page Jun 16, 2017 · 20 revisions

This file contains an array of template objects.

'struct'

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, using the id as the tag, this struct:

nav toggle toggleicon / / walker /

Turns into this code

<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.

Template Object

A template object looks like this:

{
    "id": "yourid",
    "depth": 1,
    "struct": "nav toggle toggleicon / / walker /",
    "lvl": []
}
  • id is what you use to get this template when calling flexwalker()
  • depth is the menu depth and will override other walker depth arguments
  • struct describes the structure around the nav menu and its position within it

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.

Clone this wiki locally