// you’re reading...

CMS

Growing your navigation beyond the basic tree


Adrian developed this when we were working together and I’ve shamelessly used it again and again as it’s so damn useful!

Not every site sticks to the basic tree structure offered by Navigation Manager. Sometimes you need to include external sites into the navigation structure, or even *ShockHorror!* make a page appear in more than one location. Current Navigation Manager doesn’t do external URLs and it certainly doesn’t like a page being in a site twice.

Thankfully render tags will allow you to work around these limitations in a fairly simple manner. What we are going to do is effectively turn some of our pages into redirectors for Navigation Manager.

To start with we need to go into our base page and add a few extra fields. One is a standard text field (stf_externalUrl) , the next is an anchor (anc_internalUrl) and the last is an option list (opt_linkType) that helps us tell navigation manager which link type we’re going to be using.

Technically we don’t need the option list, but it saves confusion if someone fills in both of your new fields by  mistake. In this option list we’re going to set two options Internal and External. We will use blank as the default, so unless the list is specifically set, it will write out the links as normal. 

I’m not going to create an entire navigation template, but what I will do is show you an example of how you can change what is written out by Navigation Manager.

We will start off by creating the smartEdit rule. We always want to be able to get back to our page so we can change the link to something else, or change the link title. In the following piece of code we’re creating the link and then checking to see what render mode we are in. CurrentRenderMode as been covered in previous articles, so I’ll refer you there rather than duplicating efforts. Once we’ve output the page URL we’re going to finish off the link with the page headline.  

 

<htmltext><a href="</htmltext>
<if>
    
<query valuea="Context:CurrentRenderMode" operator="==" valueb="Int:1">

<htmltext><%!!Context:CurrentIndex.GetUrl()!!%></htmltext>
    
</query>


</if>

<htmltext>"><%!!Context:CurrentIndex.Headline!!%></a></htmltext>

 

Now we have the basic structure we’ll look at expanding it out to handle our different options

 

<htmltext><a href="</htmltext>
<if>
    
<query valuea="Context:CurrentRenderMode" operator="==" valueb="Int:1">
  
<htmltext>
<%!!Context:CurrentIndex.GetUrl()!!%></htmltext>

</query>

<query type="else">
<if>
<query valuea="<%!!Context:CurrentIndex.Page.Elements.GetElement(opt_linkType).GetHtml()" operator="==" valueb="internal">
<htmltext><%!!Context:CurrentIndex.Page.Elements.GetElement(anc_internalUrl).GetHtml()!!%></htmltext> </query>
<query type="else">
 <if>
<query valuea="<%!!Context:CurrentIndex.Page.Elements.GetElement(opt_linkType).GetHtml()" operator="==" valueb="external">
 <htmltext><%!!Context:CurrentIndex.Page.Elements.GetElement(stf_externalUrl).GetHtml()!!%></htmltext>
</query>
<query type="else">
<htmltext><%!!Context:CurrentIndex.GetUrl()!!%></htmltext>
</query>
</if>
</query>
</if>
</query>

</if>
 <htmltext>">
<%!!Context:CurrentIndex.Headline!!%></a></htmltext>

What we’ve done here is to check the value of opt_linkType. If it’s set to show the internal Url we write out our anchor. Then we check to see if it’s set to external, if it is, we write out stf_externalUrl. If all else fails, we write out the normal link and pretend nothing happened.

And there you have it. the ability to add internal or external links into your otherwise rigid navigation structure. 

You will need to remember to use this piece of code in all your navigation templates, otherwise people will end up on your redirect page rather than where you intended them to be.

Share and Enjoy:
  • Print
  • email
  • Twitter
  • Digg
  • Reddit
  • StumbleUpon
  • Google Bookmarks
  • del.icio.us
  • MisterWong
  • Facebook
  • LinkedIn

No related posts.

About the author:

Paul Smith Paul lives in sunny England and is now technical consultant for the new, UK based branch of ecomplexx. Apart from web stuff, Paul is also interested in photography and collecting/listening to music and is never seen without his beloved ipod!

Discussion

9 comments for “Growing your navigation beyond the basic tree”

  1. Paul,

    Great article! I don’t quite understand why you create 2 different elements for external vs internal links. You can accomplish both from the anc_internalUrl element. You could choose either Assign URL (external) or Connect Existing Page (internal).

    Maybe I’m just missing something…

    Eric

    Posted by Eric Juden | April 1, 2009, 6:30 pm
  2. Hi Eric,

    for external links it’s best practice to use a standard field. If your site has multiple languages, the external links might link to different documents, e.g. domain.com/de/, domain.com/es/file_in_spanish.pdf, etc.

    If you use an anchor instead, the values are always the same in all language variants.

    Posted by Frederic Hemberger | April 1, 2009, 6:42 pm
  3. Thanks Frederic,

    Makes perfect since.

    Eric

    Posted by Eric Juden | April 1, 2009, 7:48 pm
  4. Paul,
    thanks for the nice article. We are using exactly the same approach for our Navigation Manager. However, we found one really big problem with cross project linking. We created anc_RefernceOtherProject element to refernce a page from another project.

    The render tag Context:CurrentIndex.Page.Elements.GetElement(anc_RefernceOtherProject).GetHtml() returns empty value if page belongs to another project. If page link stays within the same project this tag works just fine.

    So just a warining for everyone…

    Irina

    Posted by Irina Krasteleva | April 15, 2009, 3:47 pm
  5. Thanks for the heads up Irina, I’ve not tried cross linking projects yet, so it’s useful to know there are limitations

    Paul

    Posted by Paul Smith | April 16, 2009, 10:05 am
  6. Paul,

    Great article, helps with a current project that has both widespread duplicate internal links and a few external links.

    Posted by Kent J | November 5, 2009, 11:28 pm
  7. Hi Paul,

    I would like to implement something without jumping to the original point of the navigation entry. Any idea how this could be done?

    Thanks in advance,
    Conny

    Posted by Conny G | January 21, 2010, 3:33 pm
  8. Hey Conny, if you want to create an entry point let’s say in the third level of your navigation, then you just have to create a navigation area and set the navigation templates for this one to the specific level.
    Is that working for you?

    Posted by Markus Giesen | January 22, 2010, 12:01 am
  9. Hi Markus,
    sorry for my delayed answer – everything worked and my problem is solved!
    Thanks :-)

    Posted by Conny G | March 3, 2010, 10:00 am

Post a comment



Stay up to date! - Get notified about followup comments

If you don't feel the urge to comment but wish to stay in the loop:
Just enter your email and subscribe to new comments.

Subscribe without commenting

Recent Tweets

  • RT @AirKraft: Transport Canada breakout: they manage 80K pages and 300K assets with WSM(RedDot). Wow! #OTCW 2010-11-11
  • The RedDot usergroup session 'Future of WCM' is in National Harbor 7, now. See you there! #otcw 2010-11-11
  • RT @yttergren: @AirKraft: Calling all WSM(RedDot) devs: share your solutions on http://bit.ly/bgPIof EVERY solution can win an iPad #OTCW 2010-11-10
  • Come to the Solution Exchange session. Enhance your (#reddot) CMS project! Chesapeake 12, 3:20pm #otcw Looking forward to see you there! 2010-11-10
  • More updates...