Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Connie DeCinko 931 posts 1160 karma points
    Mar 22, 2016 @ 17:09
    Connie DeCinko
    0

    Add link target based on target page document type

    In my XSLT I build a sub menu with a list of hyperlinks. I'd like to add some additional code. I recently created a document type for PDF documents that is a content node wrapper around a media item. Those items now show up in my sub menu. When a user clicks them, I want them to open in a new window or new tab. If I try and do that in the wrapper template, modern browsers such as Chrome block the action. A popup is blocked if not initiated by the user such as via a click. So, I need to open the new tab with the click, which then redirects to the PDF.

    Here is my current snippet for a typical list item:

    <li>
        <a href="{umbraco.library:Replace(umbraco.library:NiceUrl(@id),'www.azbar.stg',umbraco.library:RequestServerVariables('SERVER_NAME'))}">
            <xsl:value-of select="@nodeName"/>
        </a>
    </li>
    

    How can I reference the document type and conditionally add a target to my anchor tag?

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Mar 22, 2016 @ 22:31
    Jan Skovgaard
    0

    Hi Connie

    It's been a while since I did XSLT myself unfortunately.

    However I think you should be able to do something like the following

    <li>
        <a href="{umbraco.library:Replace(umbraco.library:NiceUrl(@id),'www.azbar.stg',umbraco.library:RequestServerVariables('SERVER_NAME'))}">
            <!-- If the niceUrl contains .pdf then add the target attribute to the link with a value of _blank to open it in a new window-->
            <xsl:if test="contains(umbraco.library:NiceUrl(@id),'.pdf')">
                 <xsl:attribute name="target">
                      <xsl:text>_blank</xsl:text>
                 </xsl:attribute>
            </xsl:if>
            <xsl:value-of select="@nodeName"/>
        </a>
    </li>
    

    Instad of using contains you can also consider using the substring method perhaps.

    Does this work?

    /Jan

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies