custom_menu_macros.html
1 <#-- Init gloable counter -->
2 <#if !dropdownDivCounter??>
3 <#assign dropdownDivCounter = 0>
4 </#if>
5
6 <#--
7 Macro: renderMenu
8
9 Description: Generate a menu.
10
11 Parameters:
12 - currentMenu (customMenu): Menu to displayed
13 - sitePath (string, optional): sitePath of current page
14 - currentDepth (Integer, optional): current depth of submenu
15 - maxDepth (Integer, optional): Max depth to display submenu
16 - mainNavLutece (Boolean, optional): true if menu is displayed in default navBarLutece, false else.
17 -->
18 <#macro renderMenu currentMenu sitePath="" currentDepth=1 maxDepth=1 mainNavLutece=false>
19 <#if currentMenu.listItems?? && (currentMenu.listItems?size > 0)>
20 <ul class="custom-submenu-list">
21 <@renderMenuItems menu=currentMenu sitePath=sitePath currentDepth=currentDepth mainNavLutece=mainNavLutece maxDepth=maxDepth/>
22 </ul>
23 </#if>
24 </#macro>
25
26 <#--
27 Macro: renderMenuItems
28
29 Description: Generate items of a menu
30
31 Parameters:
32 - menu (customMenu): menu to displayed. It contains the list of items.
33 - sitePath (string, optional): sitePath of current page
34 - classItem (string, optional): class of li tag
35 - currentDepth (Integer, optional): current depth of submenu
36 - maxDepth (Integer, optional): Max depth to display submenu
37 - mainNavLutece (Boolean, optional): true if menu is displayed in default navBarLutece, false else.
38 -->
39 <#macro renderMenuItems menu sitePath="" classItem="" currentDepth=1 maxDepth=1 mainNavLutece=false >
40 <#if menu??>
41 <#list menu.listItems as item>
42 <#assign itemUrl = buildItemUrl(item, sitePath) />
43 <#if item.type!="menu">
44 <li class="<#if mainNavLutece>${classItem}<#elseif currentDepth > 1>custom-submenu-item-depth-${currentDepth?string}<#else>custom-submenu-item</#if>">
45 <a href="${itemUrl}" <#if item.type=='external_url'>target=<#if item.isBlank()?? && item.isBlank() >"_blank"<#else>"_self"</#if></#if>>
46 ${item.label!}
47 </a>
48 </li>
49 <#else>
50 <#if currentDepth<=maxDepth>
51 <li class="<#if mainNavLutece>${classItem} dropdown<#elseif currentDepth > 1>custom-submenu-item-dropdown-depth-${currentDepth?string}<#else>custom-submenu-item-dropdown</#if>">
52 <#assign dropdownDivCounter = dropdownDivCounter + 1>
53 <#if mainNavLutece>
54 <a class="nav-link dropdown-toggle" id="dLabelSUBMENU${item.sourceItemId!''}-${dropdownDivCounter!}" role="button" data-bs-toggle="dropdown" role="button" aria-expanded="false" href="${sitePath}#SUBMENU${item.sourceItemId!''}-${dropdownDivCounter!}">
55 ${item.label}
56 </a>
57 <div class="dropdown-menu" aria-labelledby="dLabelSUBMENU${item.sourceItemId!''}-${dropdownDivCounter!}">
58 <div class="dropdown-menu-columns">
59 <div class="dropdown-menu-column">
60 <ul>
61 <@renderMenuItems menu=item.subMenu sitePath=sitePath currentDepth=currentDepth+1 mainNavLutece=mainNavLutece/>
62 </ul>
63 </div>
64 </div>
65 </div>
66 <#else>
67 <div class="custom-submenu-span-depth-${(currentDepth+1)?string}">${item.label}</div>
68 <ul class="custom-submenu-list-depth-${(currentDepth+1)?string}">
69 <@renderMenuItems menu=item.subMenu sitePath=sitePath currentDepth=currentDepth+1 maxDepth=maxDepth/>
70 </ul>
71 </#if>
72 </li>
73 </#if>
74 </#if>
75 </#list>
76 </#if>
77 </#macro>
78
79 <#--
80 Function to build the URL based on the item type
81 Possible types: "page", "xpage", "external_url", "menu"
82 -->
83 <#function buildItemUrl item sitePath="">
84 <#if !item.type??>
85 <#return item.url!"">
86 </#if>
87
88 <#switch item.type>
89 <#case "page">
90 <#if item.url?? && item.url != "">
91 <#return sitePath + "?" + item.url>
92 <#else>
93 <#return sitePath + "?page_id=" + item.sourceItemId!"">
94 </#if>
95 <#break>
96
97 <#case "xpage">
98 <#if item.url?? && item.url != "">
99 <#return sitePath + "?" + item.url>
100 <#else>
101 <#return sitePath + "?page=" + item.strSourceItemId!"">
102 </#if>
103 <#break>
104
105 <#case "external_url">
106 <#return item.url!"">
107 <#break>
108
109 <#case "menu">
110 <#return "#">
111 <#break>
112
113 <#default>
114 <#return item.url!"">
115 </#switch>
116 </#function>