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.
<reddot:cms> <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> </reddot:cms>
Now we have the basic structure we’ll look at expanding it out to handle our different options
<reddot:cms> <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> </reddot:cms>
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.