Managed Nav>Landing Pages open in a New Window by using the Snippet Item Template

I’ve worked on a multiple Rhythmyx projects, where we wanted the landing page of a Navon, to open in New Window.
This was usually a business requirement if the Landing page was an External link or a PDF file.

One solution is to add a field to the Navon content type to flag if the Navon link should open in a new window, which is what was done at the majority of the projects I worked on.

On my last project, I thought it would be better to actually use the Snippet link template, that was assigned to the Nav Landing Page Slot,
which is the expected behavior of a regular slot.

Slot(ID: Nav Landing Page (510)
[TABLE=“class: grid”]

Item Title (ID)

Item Type (ID)

Item Template (ID)

About Us (1234)

Landing Page (###)

rffSnTitleLink(###)

[/TABLE]

Standard code to render a Landing Page Link

#macro(showlandingpage $node)

#set($title = $node.getProperty(“rx:displaytitle”).String)
#set($landing_page = $node.getProperty(“nav:url”).String)
#set($submenu = $node.getNodes(“nav:submenu”))
#set($axis = $node.getProperty(“nav:axis”).String)
#set($indentclass = $axis.toLowerCase())

#if ( $landing_page )
<li class="$indentclass">
<a href="$landing_page">$title</a>
</li>
#end

#end

#showlandingpage ($node)

The above code will open the Landing page in the same window, even if the snippet template rffSnTitleLink did open the link in a new Window, which is how you expect to behave in a normal slot.

Opening the Landing Page in the window defined by the Snippet template

Slot(ID: Nav Landing Page (510)
[TABLE=“class: grid”]

Item Title (ID)

Item Type (ID)

Item Template (ID)

About Us (1234)

Landing Page (###)

rffSnTitleLinkNewWindow(###)

[/TABLE]

The Snippet template rffSnTitleNewWindow would have the following code
<a href="${pagelink}" target="_blank">${displaytext}</a>

So we need code to detect if the Landing Page opens in target=”_blank” or not.
Which is what the following macro does

##Returns the taget of _blank if the Landing Page Snippet Link contains target="_blank"
##Used for opening a Landing Page link in a new window
#macro(landingPage_Target $node)##
##Code to figure out if the Landing Page opens in a new window
#set($slotContent="#node_slot($node ‘rffNavLandingPage’ ‘’ ‘’ ‘’ ‘’ ‘’)")##
#set($target="")##
#if($slotContent.indexOf(“target=”)>0 && $slotContent.indexOf("_blank")>0)##
#set($target=" target=_blank")##
#end##

$!{target}##
#end##

This macro can then be called from standard code for displaying a landing page link

#macro(showlandingpage $node)

#set($title = $node.getProperty(“rx:displaytitle”).String)
#set($landing_page = $node.getProperty(“nav:url”).String)
#set($submenu = $node.getNodes(“nav:submenu”))
#set($axis = $node.getProperty(“nav:axis”).String)
#set($indentclass = $axis.toLowerCase())

#if ( $landing_page )
<li class="$indentclass">
##<a href="$landing_page">$title</a>
##Call the macro landingPage_Target
<a href="$landing_page" #landingPage_Target($navon)>$title</a>
</li>
#end