Forum

Thread tagged as: Question, Problem

How do I get my main nav links to open in a new window if they are external URLs...

A couple of the links in my main navigation link to external websites.

I've gone through the A page, Page already exists or is a link only, add an external URL method.

I want these to open in a new tab instead of taking you away from the site. Is this possible? Link to my test site is below, it's the Cinema and Gym links in the nav (top right).

https://capitol.kubiaktest.co.uk/

Emily Taylor

Emily Taylor 0 points

  • 5 years ago
Simon Clay

Simon Clay 127 points

Hi Emily, how about adding this into the nav template:

<perch:if id="pagePath" contains="http"> target="_blank" </perch:if>

So, if using the default item.html template it would look something like:

<perch:before>
    <ul>
</perch:before>
        <li<perch:if exists="current_page"> class="selected"</perch:if><perch:if exists="ancestor_page"> class="ancestor"</perch:if>>
            <a href="<perch:pages id="pagePath" />" <perch:if id="pagePath" contains="http"> target="_blank" </perch:if>><perch:pages id="pageNavText" /></a>   
            <perch:pages id="subitems" encode="false" />
        </li>
<perch:after>
    </ul>
</perch:after>

Unfortunately I couldn't get this to work...

<a href="<perch:pages id="pagePath" />"<perch:if id="pagePath" contains="http"> target="_blank"</perch:if>><perch:pages id="pageNavText" /></a>

I'm guessing contains="" only works with perch:content???