silverstripe-framework/docs/en/02_Developer_Guides/01_Templates/How_Tos/01_Navigation_Menu.md

35 lines
930 B
Markdown
Raw Normal View History

2014-10-13 09:49:30 +02:00
title: How to Create a Navigation Menu
# How to Create a Navigation Menu
In this how-to, we'll create a simple menu which you can use as the primary navigation for your website. This outputs a
top level menu with a nested second level using the `Menu` loop and a `Children` loop.
**mysite/templates/Page.ss**
:::ss
<ul>
<% loop $Menu(1) %>
<li>
2015-11-23 21:10:47 +01:00
<a href="$Link" title="Go to the $Title page" class="<% if $isCurrent %>current<% else_if $isSection %>section<% end_if %>">
2014-10-13 09:49:30 +02:00
$MenuTitle
</a>
2015-11-23 21:10:47 +01:00
<% if $isSection %>
2014-10-13 09:49:30 +02:00
<% if $Children %>
2015-09-30 03:19:20 +02:00
<ul class="secondary">
2014-10-13 09:49:30 +02:00
<% loop $Children %>
2015-11-23 21:10:47 +01:00
<li class="<% if $isCurrent %>current<% else_if $isSection %>section<% end_if %>"><a href="$Link">$MenuTitle</a></li>
2014-10-13 09:49:30 +02:00
<% end_loop %>
2015-09-30 03:19:20 +02:00
</ul>
2014-10-13 09:49:30 +02:00
<% end_if %>
<% end_if %>
</li>
<% end_loop %>
</ul>
## Related
* [Template Syntax](../syntax)
2015-09-30 03:19:20 +02:00
* [Common Variables](../common_variables)