Related Links umbraco DataType

Transforming the Related Links XML

Related Links is a new standard DataType in umbraco v4. Add a property of this type to any DocType, then when editing content of that type you'll have available a special control for entering and storing related web-links, internal or external. Entering and storing is one thing, but how to display them. . .


. . .turns out to be easy, too.  There's an example XSLT, "Related Links", available as a base when you create a new XSLT in the developer section.  Along with a macro for the XSLT, you are ready to list the links.  I added some class names for easy CSS styling, and a couple tests for existence, and a text parameter for my macro, as an optional header.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [
  &lt;!ENTITY nbsp "&#x00A0;">
]>
<xsl:stylesheet
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxml="urn:schemas-microsoft-com:xslt"
    xmlns:umbraco.library="urn:umbraco.library"
    exclude-result-prefixes="msxml umbraco.library">


  <xsl:output method="xml" omit-xml-declaration="yes" />

  <xsl:param name="currentPage"/>
  
  <!-- Input the related links property alias defined on your DocType here -->
  <xsl:variable name="propertyAlias" select="string('relatedLinks')"/>
  <xsl:variable name="headline" select="string(/macro/headline)" />
  <xsl:template match="/">
    <!-- Are there any links to list? -->
  <xsl:if test="$currentPage/data [@alias = $propertyAlias]/links" >
    <!-- The fun starts here -->
    <xsl:choose>
        <xsl:when test="$headline != ''"><h4><xsl:value-of select="$headline"/></h4></xsl:when>
        <xsl:otherwise><h4>Related Links</h4></xsl:otherwise>
    </xsl:choose>
    <ul class="linklist">
      <xsl:for-each select="$currentPage/data [@alias = $propertyAlias]/links/link">
        <li>
          <xsl:element name="a">
            <xsl:if test="./@newwindow = '1'">
              <xsl:attribute name="target">_blank</xsl:attribute>
            </xsl:if>
            <xsl:choose>
              <xsl:when test="./@type = 'external'">
                <xsl:attribute name="href">
                  <xsl:value-of select="./@link"/>
                </xsl:attribute>
              </xsl:when>
              <xsl:otherwise>
                <xsl:attribute name="href">
                  <xsl:value-of select="umbraco.library:NiceUrl(./@link)"/>
                </xsl:attribute>
              </xsl:otherwise>
            </xsl:choose>
            <xsl:value-of select="./@title"/>
          </xsl:element>
        </li>
      </xsl:for-each>
    </ul>

    <!-- Live Editing support for related links. -->
    <xsl:value-of select="umbraco.library:Item($currentPage/@id,$propertyAlias,'')" />
    </xsl:if>
  </xsl:template>

</xsl:stylesheet>
Check XHTML  «  feebdack.com  Copyright ©  Xander Lih  2000-2009   »  Check CSS