A menu template is like a page template. It generates the HTML (including "id" and "class" attributes used by CSS) necessary to present the menu data. The CSS associated with a page template that includes a "menu" Smarty tag (possibly using an explicit menu template specified with the optional "template" parameter) is used to style the menu.
Generally, most menu templates take a list of "nodes" containing the menu data and format the desired data as an HTML list. Creating your own menu template, you could choose to use an ordered list ("") or an "unordered" (""--i.e. "bullet" list) or a definition list ("dl") or an HTML table or a paragraph containing menu entries separated by line breaks ("
") or... Basically, the menu template enables you to format the menu data as necessary to meet your formatting and presentation (by adding "id" and "class" attributes) needs.
As an example of why you might write your own menu template, you might want to select a subset for presentation of the nodes selected by a given set of "menu" Smarty tag parameters. In my case, I have a "page" that exists outside of the rest of my menu hierarchy and that is excluded from the menu system that is implemented to return a formatted menu suitable for use in legacy static HTML pages that have not yet been manually imported into CMSMS. These pages use a server-side include to access the CMSMS page I created.
Because the "page" I created is outside the sub-tree of the menu hierarchy that I use in the desired menu, I cannot use the "start_level" parameter. Using a combination of the "start_page" or "start_element" parameters with the "show_root_siblings" parameter resulted in more than twice as many SQL queries and, consequently, very poor performance when compared to just using the "start_page" or "start_element" parameter to select the parent node of all of the child nodes I actually wanted to list in my menu. (This is one of several significant performance problems with the current Menu Manager module.) My solution for the time being is to use a custom menu template that simply skips the first (i.e. "root" or ultimate parent node of all of the selected nodes) when formatting up my HTML list.
The relevant portion of the menu template looks like:
Code: Select all
{foreach from=$nodelist item=node}
{if $node->index > 0}
...
{/if}
{/foreach}
(I would prefer to pass a node list omitting the first element to the "foreach" tag, but that is not trivially accomplished using Smarty. It requires an escape to full PHP as far as I can tell.)
Because the same menus may be used in a variety of pages associated with different page templates, menu templates are the mechanism for creating reusable menus for use in multiple page templates. While the included menu templates may meet your needs, being able to create your own menu templates can be very useful when they don't.