Valid for Sitecore 5.3.1
12.  Link
Prev Next

A field of "link" type contains link to another Sitecore document, file in media library, external URL, JavaScript, email address or anchor in the same document. The easiest way of displaying links in XSL rendering is using Link XSL Control:

<sc:link field="My Link"/>

XslHelper.link (sc:link) function can be used for the same purpose:

<xsl:value-of select="sc:link('My Link',.)" disable-output-escaping="yes"/>

There is another version of link function that accepts three parameters:

<xsl:value-of select="sc:link('My Link',.,'Test link')" disable-output-escaping="yes"/>

The first parameter contains the name of the field containing the link data. The second parameter contains the item you are working on (as with the fld function). The third parameter contains the link text (what the user sees on the website).

Omitting the third parameter will insert the text that was defined for the link in the Sitecore client (that is "My Link", according to the example below).

Note: the third parameter can also contain HTML text. This enables you to make links containing formatted text, provided that you use escape characters instead of special characters, e.g. &lt;b&gt;hi&lt;/b&gt; or images, e.g. &lt;IMG ...&gt;.

Read more about Escape Sequences.

If you want your own custom link you can use XslHelper.fld function (sc:fld) with sub-properties:

url: <xsl:value-of select="sc:fld(‘My Link’,.,'url')"/>

anchor: <xsl:value-of select="sc:fld(‘My Link’,.,'anchor')"/>

target: <xsl:value-of select="sc:fld(‘My Link’,.,'target')"/>

type: <xsl:value-of select="sc:fld(‘My Link’,.,'linktype')"/>

text: <xsl:value-of select="sc:fld(‘My Link’,.,'text')"/>

css class: <xsl:value-of select="sc:fld(‘My Link’,.,'class')"/>

title (alt): <xsl:value-of select="sc:fld(‘My Link’,.,'title')"/>

id: <xsl:value-of select="sc:fld(‘My Link’,.,'id')"/>

Note: the ‘id’ sub-property represents the GUID of the target item.

For instance, you may use the following construct:

<a href="{sc:fld('My Link',.,'url')}" class="{sc:fld('My Link',.,'class')}"><xsl:value-of select="sc:fld('My Link',.,'text')"/></a> 

To generate the proper url in relation to the link type, you can use the assisting function XslHelper.url (sc:url) :

<xsl:value-of select="sc:url('link',.)"/>


Prev Next