Copied to clipboard

Flag this post as spam?

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


  • Devin 87 posts 251 karma points
    May 27, 2015 @ 09:44
    Devin
    0

    Force the use of HTTP

    I have a basic textstring which allows people to type in an external link. The problem occurs when they don't put "http://", it breaks the link. How do I force the use of HTTP? Or, if they put HTTP:// leave it out, otherwise put it in for them.

    Thanks,

    <a href="{$ecmLink}" class="downloadLink" target="_blank">
       
    <div class="projectTitle">
           
    <xsl:value-of select="@nodeName"/>
           
    <!-- small attachment icon -->
           
    <div class="downloadIcon"><img src="/images/icons/download.png" /></div>
       
    </div>
    </a>
  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 7x admin c-trib
    May 27, 2015 @ 09:47
    Chriztian Steinmeier
    1

    Hi Devin,

    Here's what I usually do - you can rewrite the attribute - don't worry, only a single href attribute will be output :-)

    <a href="{$ecmLink}" class="downloadLink" target="_blank">
        <!-- Rewrite the `href` attribute if it doesn't start with 'http' -->
        <xsl:if test="not(starts-with($ecmlink, 'http'))">
            <xsl:attribute name="href"><xsl:value-of select="concat('http://', $ecmlink)" /></xsl:attribute>
        </xsl:if>
        <div class="projectTitle">
            <xsl:value-of select="@nodeName"/>
            <!-- small attachment icon -->
            <div class="downloadIcon"><img src="/images/icons/download.png" /></div>
        </div>
    </a>
    

    /Chriztian

  • Devin 87 posts 251 karma points
    May 27, 2015 @ 09:51
    Devin
    0

    Thanks for such a quick response! It works flawlessly of course. :)

Please Sign in or register to post replies

Write your reply to:

Draft