Change log

menu

This component outputs data relating to a specific Menu including all menu items and any child sub-items.

{% component type: "menu", alias: "<menu_alias>" %}

Parameters and Options

Parameter
Values
Required
Description
type
menu

This is the name of the entity that needs to be used for the component retrieving function.

alias
<alias_name>
The alias name of the module.
layoutGroup
Default (default)
<Your Layout Group>
-
The layout group name you want to use for rendering the component. The layout group name is referenced from the available Layout Groups of the alias specified. If the parameter is blank or has an incorrect referenced Layout Group then the component will use the system 'Default' Layout Group.
collectionVariable
<yourLiquidVariableName>

Assigns the data to a Liquid collection enabling further access to the data on the Page or Template using Liquid.
If using this parameter, the module will not render its layout.

Your collectionVariable value must only contain English letters, numbers or underscores. Spaces or special characters are not supported.

<customParameter>
<your custom value>

You can add your own additional parameters (name/value pairs) to the Component tag. These will be passed to the Components Layout (and the collectionVariable if used) for use via Liquid.

Your <customParameter> name must only contain English letters, numbers or underscores. Spaces or special characters are not supported.

You can use HTML as the value here, just be sure to change any double quotes in your HTML to single quotes.

Also, see here for a tutorial on using Custom Paramters.

Liquid Output

The below menu example includes 3 top level menu items with 2 sub menu items and represents the typical data structure you will see from this Component.

{
  "Name": "DEMO Menu Example",
  "Alias": "demo_menu_example",
  "LayoutGroup": "",
  "Items": [
    {
      "id": 388,
      "ItemId": null,
      "ItemName": "Menu Item 1",
      "ItemUrl": "#",
      "ItemTargetFrame": null,
      "ItemClass": null,
      "ItemTitle": null,
      "ItemCustomAttribute": null,
      "ItemEnabled": true,
      "ReleaseDate": null,
      "ExpiryDate": null,
      "Items": []
    },
    {
      "id": 946,
      "ItemId": null,
      "ItemName": "Menu Item 2",
      "ItemUrl": "/demo-cs/basic-menu-example",
      "ItemTargetFrame": null,
      "ItemClass": null,
      "ItemTitle": null,
      "ItemCustomAttribute": null,
      "ItemEnabled": true,
      "ReleaseDate": null,
      "ExpiryDate": null,
      "Items": []
    },
    {
      "id": 796,
      "ItemId": null,
      "ItemName": "Menu Item 3",
      "ItemUrl": "#",
      "ItemTargetFrame": null,
      "ItemClass": null,
      "ItemTitle": null,
      "ItemCustomAttribute": null,
      "ItemEnabled": true,
      "ReleaseDate": null,
      "ExpiryDate": null,
      "Items": [
        {
          "id": 196,
          "ItemId": null,
          "ItemName": "Sub Menu Item 1",
          "ItemUrl": "#",
          "ItemTargetFrame": null,
          "ItemClass": null,
          "ItemTitle": null,
          "ItemCustomAttribute": null,
          "ItemEnabled": true,
          "ReleaseDate": null,
          "ExpiryDate": null,
          "Items": []
        },
        {
          "id": 263,
          "ItemId": null,
          "ItemName": "Sub Menu Item 2",
          "ItemUrl": "#",
          "ItemTargetFrame": null,
          "ItemClass": null,
          "ItemTitle": null,
          "ItemCustomAttribute": null,
          "ItemEnabled": true,
          "ReleaseDate": null,
          "ExpiryDate": null,
          "Items": []
        }
      ]
    }
  ],
  "Params": {
    "type": "menu",
    "alias": "demo_menu_example",
    "layoutgroup": "",
    "collectionvariable": "menuExample"
  }
}

Accessing the Data

JSON Output

You can output the full JSON for your component data by referencing the root Liquid object {{this}} in your module’s layouts, or directly on your page, if using the collectionVariable parameter in your component tag.

For example:

{% component type: ... collectionVariable: "myData" %}

You can then render the JSON like so:

{{myData}}

For more details on using this approach, see Part 2 of the free ‘Learning Liquid Course’.

Rendering Property Values

As an alternative, you can instead output the menu data directly on the Page or Template via a Liquid Collection if collectionVariable was added to the Component tag.

An example using collectionVariable with value "menuData" is as follows:

{% component type: "menu", alias: "menu_example", collectionVariable: "menuData" %}

Looping through the collection to render all the top level item names in a list:

<ul>
{% for m in menuData.items %}
    <li>{{m['itemname']}}</li>
{% endfor %}
</ul>

Now, testing for sub menu items and nesting them in the list:

<ul>
{% for m in menuData.items %}
    <li>{{m['itemname']}}
      {% if m.items.size > 0 %}
        <ul>
            {% for subm in m.items %}
                <li>{{subm.itemname}}</li>
            {% endfor %}
        </ul>
        {% endif %}
    </li>
{% endfor %}
</ul>

Accessing a specific item within the collection. In this case the third menu item name (zero based index):

{{menuData.items[2]['itemname']}}


Related Articles

  • Content Modules
    Menus

    Menus allow the easy creation and management of dynamic navigation elements. These can be rendered anywhere throughout your site, whether in content templates, pages, snippets or most other layouts.

External Resources


Please let us know if you have any other contributions or know of any helpful resources you'd like to see added here.


Questions?

We are always happy to help with any questions you may have.
Visit the Treepl Forum for community support and to search previously asked questions or send us a message at support@webinone.com and we will consult you as soon as possible.