This project has moved. For the latest updates, please go here.

use of custom fields in navigation?

Nov 5, 2010 at 6:11 PM

Hi there,

is it possible to add (or use) a custom field for the navigation? I need to have different colors for each link in navigation.

<div id="menu">
<ul>
#foreach($link in $macros.NavigationLinks())
<li style="background-color:CUSTOM.FIELD;"><a href="$link.Url">$link.Text</a></li>
#end
</ul>
</div>

Thanks in advance!

Markus

Nov 5, 2010 at 6:19 PM

On more question: I have created an own theme. Is there a macro to include the link to the theme files? Now I use the following code:

<img src="/files/themes/$data.Site.Theme/images/image.gif">

Thanks!

Markus

Editor
Nov 5, 2010 at 6:24 PM

Markus,

To your second question:  $macros.ThemeFile("images/image.gif")

More info on macros:  http://graffiticmstips.com/tips/graffiticms/using-graffiti-cms-macros/

Regards,
Brian 

Nov 6, 2010 at 12:50 AM

Thanks Brian, works like a charm!

I found a solution for my first question. I have no clue if it is a good idea, but I added a color-field to the NavigationSettings in the ObjectStore. So I can use

<div id="menu">
  <ul>
    #foreach($link in $macros.NavigationLinks())
    <li style="background-color:$link.Color;"><a href="$link.Url">$link.Text</a></li>
    #end
  </ul>
</div>

Regard,
Markus

Coordinator
Nov 8, 2010 at 5:38 AM
Hussl wrote:

Thanks Brian, works like a charm!

I found a solution for my first question. I have no clue if it is a good idea, but I added a color-field to the NavigationSettings in the ObjectStore. So I can use

 

<div id="menu">
  <ul>
    #foreach($link in $macros.NavigationLinks())
    <li style="background-color:$link.Color;"><a href="$link.Url">$link.Text</a></li>
    #end
  </ul>
</div>

 

Regard,
Markus

You certainly CAN do it that way, but that is something that we definitely would not be adding to the system's code base, which means that if you upgrade to a newer version at some point, you're going to have to reapply those changes or they will be lost.

You may want to look into the CSS attribute selectors. You can have a CSS rule that applies for a specific href path. That will kill two birds with one stone - you can remove the custom code from the base and also remove your inline styles, instead using styles in a CSS file.

Nov 11, 2010 at 3:35 PM

This will give you some classes you can style:

<div id="menu">
<ul>
#foreach($link in $macros.NavigationLinks())
<li class="$link.Url.Replace("/"," ")"><a href="$link.Url">$link.Text</a></li>
#end
</ul>
</div>

<div id="menu">
<ul>
#foreach($link in $macros.NavigationLinks())
<li class="item-$count"><a href="$link.Url">$link.Text</a></li>
#end
</ul>
</div>

Nov 12, 2010 at 7:09 AM

Thanks Michael,

your 2nd solution is exactly what I was looking for. Didn't know that there is a counter.

Best regards

Markus

 

Nov 16, 2010 at 4:45 PM

BTW you might run into an issue if you use Custom Fields to hide an item in the loop. The counter that comes with Graffiti will not work right and the order of the increments may be lost. The easiest way to get around it is to do this.

 

#set ($trueCount = 0)
<div id="menu">
  <ul>
    #foreach($link in $macros.NavigationLinks())
    #set ($trueCount = $trueCount + 1)
    <li class="item-$trueCount"><a href="$link.Url">$link.Text</a></li>
    #end
  </ul>
</div>