Skip to content

Instantly share code, notes, and snippets.

@sandermarechal
Created January 13, 2015 13:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sandermarechal/c47eba91ff675d5a8de9 to your computer and use it in GitHub Desktop.
Save sandermarechal/c47eba91ff675d5a8de9 to your computer and use it in GitHub Desktop.
foundation off-canvas KnpMenu
{% extends 'knp_menu.html.twig' %}
{% block list %}
{% if item.hasChildren and options.depth is not sameas(0) and item.displayChildren %}
{% import 'knp_menu.html.twig' as knp_menu %}
{% if item.level > 0 %}
{% set listAttributes = listAttributes|merge({'class': (listAttributes.class|default('') ~ ' left-submenu')|trim}) %}
{% else %}
{% set listAttributes = listAttributes|merge({'class': (listAttributes.class|default('') ~ ' off-canvas-list')|trim}) %}
{% endif %}
<ul{{ knp_menu.attributes(listAttributes) }}>
{% if item.level > 0 %}
<li class="back"><a href="#">Back</a></li>
{% endif %}
{{ block('children') }}
</ul>
{% endif %}
{% endblock %}
{% block item %}
{% if item.displayed %}
{%- set classes = item.attribute('class') is not empty ? [item.attribute('class')] : [] %}
{% if matcher is defined %}
{%- if matcher.isCurrent(item) %}
{%- set classes = classes|merge([options.currentClass]) %}
{%- elseif matcher.isAncestor(item, options.depth) %}
{%- set classes = classes|merge([options.ancestorClass]) %}
{%- endif %}
{%- endif %}
{%- if item.actsLikeFirst %}
{%- set classes = classes|merge([options.firstClass]) %}
{%- endif %}
{%- if item.actsLikeLast %}
{%- set classes = classes|merge([options.lastClass]) %}
{%- endif %}
{%- set attributes = item.attributes %}
{% if item.hasChildren and options.depth is not sameas(0) and item.displayChildren %}
{%- set classes = classes|merge(['has-submenu']) %}
{% endif %}
{%- if classes is not empty %}
{%- set attributes = attributes|merge({'class': classes|join(' ')}) %}
{%- endif %}
{% import 'knp_menu.html.twig' as knp_menu %}
<li{{ knp_menu.attributes(attributes) }}>
{%- if (item.uri is not empty or (item.hasChildren and item.displayChildren)) %}
{{ block('linkElement') }}
{%- else %}
{{ block('labelElement') }}
{%- endif %}
{%- set childrenClasses = item.childrenAttribute('class') is not empty ? [item.childrenAttribute('class')] : [] %}
{%- set childrenClasses = childrenClasses|merge(['menu_level_' ~ item.level]) %}
{%- set listAttributes = item.childrenAttributes|merge({'class': childrenClasses|join(' ') }) %}
{{ block('list') }}
</li>
{% endif %}
{% endblock %}
{% block linkElement %}
{% import 'knp_menu.html.twig' as knp_menu %}
<a {% if item.uri is not empty %}href="{{ item.uri }}"{% endif %}{{ knp_menu.attributes(item.linkAttributes) }}>{{ block('label') }}</a>
{% endblock %}
{% block labelElement %}
{% import 'knp_menu.html.twig' as knp_menu %}
<label{{ knp_menu.attributes(item.labelAttributes) }}>{{ block('label') }}</label>
{% endblock %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment