X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fthemes%2Fcontrib%2Fbootstrap%2Ftemplates%2Fmenu%2Fmenu.html.twig;fp=web%2Fthemes%2Fcontrib%2Fbootstrap%2Ftemplates%2Fmenu%2Fmenu.html.twig;h=1f48ae6638d2939864538f15ac8284b0d246862d;hp=cbc5be86a5b683a0841f5784625fd0149b3f11fa;hb=af6d1fb995500ae68849458ee10d66abbdcfb252;hpb=680c79a86e3ed402f263faeac92e89fb6d9edcc0 diff --git a/web/themes/contrib/bootstrap/templates/menu/menu.html.twig b/web/themes/contrib/bootstrap/templates/menu/menu.html.twig index cbc5be86a..1f48ae663 100644 --- a/web/themes/contrib/bootstrap/templates/menu/menu.html.twig +++ b/web/themes/contrib/bootstrap/templates/menu/menu.html.twig @@ -13,44 +13,40 @@ * - localized_options: Menu link localized options. * * @ingroup templates + * + * Define a custom macro that will render all menu trees. */ #} -{% import _self as menus %} - -{# - We call a macro which calls itself to render the full tree. - @see http://twig.sensiolabs.org/doc/tags/macro.html -#} -{{ menus.menu_links(items, attributes, 0) }} - -{% macro menu_links(items, attributes, menu_level) %} - {% import _self as menus %} +{% macro menu_links(items, attributes, menu_level, classes) %} {% if items %} - {% if menu_level == 0 %} - - {% else %} - - {% endif %} + {% for item in items %} {% set item_classes = [ - item.is_expanded? 'expanded', - item.is_expanded and menu_level == 0 ? 'dropdown', + item.is_expanded and item.below ? 'expanded', + item.is_expanded and menu_level == 0 and item.below ? 'dropdown', item.in_active_trail ? 'active', ] %} - {% if menu_level == 0 and item.is_expanded %} + {% if menu_level == 0 and item.is_expanded and item.below %} - {{ item.title }} + {{ item.title }} {% else %} {{ link(item.title, item.url) }} {% endif %} {% if item.below %} - {{ menus.menu_links(item.below, attributes.removeClass('nav'), menu_level + 1) }} + {{ _self.menu_links(item.below, attributes.removeClass(classes), menu_level + 1, classes) }} {% endif %} {% endfor %} {% endif %} {% endmacro %} + +{# + Invoke the custom macro defined above. If classes were provided, use them. + This allows the template to be extended without having to also duplicate the + code above. @see http://twig.sensiolabs.org/doc/tags/macro.html +#} +{{ _self.menu_links(items, attributes, 0, classes ? classes : ['menu', 'menu--' ~ menu_name|clean_class, 'nav']) }}