Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Multiple Styles in Top Level Menu

Go to End

2 Posts   1502 Views


Community Member, 10 Posts

29 September 2010 at 3:58pm

Hi there,

Coming from a ColdFusion background I am new to Silverstripe but so far I love it, and perhaps because I have a programming background, I found ALL of the tutorials easy to understand and an absolute must for "newbies". But there is one thing that currently has me stumped, and it is to do with the styling of the top level menu items. An example to demonstrate what I wish to achieve...

Currently my included file looks like so:
<% control Menu(1) %>
<li><a href="$Link" title="Go to the $Title.XML page" class="$LinkingMode"><span>$MenuTitle</span></a></li>
<% end_control %>

That's all fine and dandy and everything works fine. But I want more than just the page name in the menu text. The above would generate based on the four pages I have allowed to display:

<li><a href="/home/" class="current"><span>Home</span></a></li>
<li><a href="/about-us/" class="link"><span>About Us</span></a></li>
<li><a href="/contact-us/" class="link"><span>Contact Us</span></a></li>
<li><a href="/news/" class="link"><span>News</span></a></li>

But what I need is something more than just the actual Menu title in the link. i.e. in the above example I want to display:
<li><a href="/home/" class="current"><span>Home</span> GORE NZ</a></li>

Then I can use CSS to make the two look different and place the additional text on a new line. Is there any way of achieving this short of *hacking* with something like:

<% control Menu(1) %>
<a href="$Link" title="Go to the $Title.XML page" class="$LinkingMode"><span>$MenuTitle</span></a>
<% if MenuTitle(home) %>
<% else %>
<% if MenuTitle(about us) %>
<% end_if %>
<% end_control %>

... although I just tried that and it adds GORE NZ to all of the navigation items. Any ideas or help appreciated.



Community Member, 10 Posts

1 October 2010 at 4:29pm

So to answer my own rather silly question, after stopping and actually thinking about it (yes I was having a "der" moment up there in my first post so I apologise for that) the simple solution is:

Extending page.php I added

function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.Content.Main', new TextField('SubNavText'), 'Content');
return $fields;

static $db = array(
'SubNavText' => 'Text'

Rebuilt the database, then in the nav include ( I added the subnavtext field.

<% control Menu(1) %>
<li><a href="$Link" title="Go to the $Title.XML page" class="$LinkingMode"><span>$MenuTitle</span> $SubNavText
<% end_control %>

did a flush, and it works fine. Again, sorry about the dumb question and this is obviously why no one replied, but that isn't always a bad thing, since finding the solution ones self and having a 'light bulb' moment is often more beneficial.