menu (Smarty extension function)
{menu} is a custom Smarty function for the construction of menus. A menu, in this context, is a set of links and text for a specific function. For example, if you are signed in, the bottom of this page has a menu with various items such as "New Comment" and "Send Feedback." If you are the owner of a page, there are even more options like "Edit" and "Delete." These menus are all created with the {menu} function.
Syntax:
{menu name="string" [ link="url" text="string" sep="string" sort=boolean prefix="string" suffix="string" ] }
{menu} is used in two ways: first, to construct a menu in memory, and, second, to insert the menu onto a page. When {menu} is invoked with the text= parameter, it adds the text item (and optionally the associated link URL) to the named menu. When invoked without the text= parameter, it inserts the named menu into the specific location. An example here might help:
{menu name="sample" text="News" link="http://news.yahoo.com"}
{menu name="sample" text="Sports" link="http://sports.yahoo.com"}
{menu name="option" text="Search" link="http://search.yahoo.com"}
<ul>{menu name="Sample" prefix="<li>" suffix="</li>" sort=true}</ul>
In this example, the first two lines add links (News and Sports) to the menu "sample." The third line adds an item "Search" to a different menu named "option." Finally, the last line inserts the menu as a list between the <ul> and </ul> tags. Note that the "option" menu does not yet appear on the page.
{menu} parameters:
- name (required): the name of the menu, whether creating or inserting.
- text: the text of the link; if there is no associated link parameter, then only the raw text is output.
- link: the URL associated with the link.
- onclick: an optional Javascript code segment for the onClick() event.
- sep: when output, a string that appears between every item on the menu.
- sort: if true, then the output menu is sorted alphabetically; otherwise, the menu items appear in the order they were added.
- title: an optional title="" tag for the link (this usually causes tooltips to appear when the mouse is hovered over the link).
- prefix, suffix: a string that appears before (prefix) or after (suffix) each menu item.
One of the advantages of using {menu} over hard-coding menus is that the menu items can be added throughout your code, and then inserted all together, much as the action menus on the bottom of these pages are.
