Copied to clipboard

Flag this post as spam?

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


  • Alex Burr 77 posts 128 karma points
    Dec 21, 2011 @ 17:10
    Alex Burr
    0

    Accessing custom Media Type properties

    Hi everyone... I've built an image carousel macro (uses the Nivo Slider) and I'm very happy so far with getting images to spin. My macro takes a Media folder as a parameter, so that after dropping the carousel macro on the page, users can update the carousel by just adding/removing images from the Media folder.

    I've added a link property (Content Picker) to the 'Image' Media Type in Umbraco, but I can't figure out the proper syntax to get my XSLT macro to actually insert a clickable link.

    Here's what I have currently...

     

    <xsl:param name="currentPage"/>
    
    <!-- Define source of files in Media Library -->
    <xsl:variable name="mediaNode" select="/macro/mediaSource" />
    <xsl:variable name="id" select="$mediaNode/Gallery/@id" />
    <xsl:variable name="width" select="/macro/width" />
    <xsl:variable name="height" select="/macro/height" />
    <!-- Displays all documents in a folder -->
    <xsl:template match="/">
        <div id="slider" class="nivoSlider theme-default" style="width: {$width}px; height: {$height}px;">
            <xsl:if test="$id">
                <xsl:variable name="folderContent" select="umbraco.library:GetMedia($id,1)" />
                <xsl:for-each select="$folderContent/Image">
                        <img src="{umbracoFile}" alt="{@nodeName}" title="{@nodeName}" />
                </xsl:for-each>
            </xsl:if>
        </div>
    </xsl:template>

     

    This correctly adds/rotates images.
    I was considering adding something like this within my <xsl:for-each> to output the link:

     

    <xsl:element name="a">
           <xsl:attribute name="href">
                <xsl:value-of select="current()/link"/>
            </xsl:attribute>
           <img src="{umbracoFile}" alt="{@nodeName}" title="{@nodeName}" />
    </xsl:element>

    But no dice. Any help on the syntax would be great! Thanks in advance. :)

     

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Dec 21, 2011 @ 18:53
    Jan Skovgaard
    0

    Hi Alex

    What have you called your link property?

    I suppose you should be able to simply just write

    <a href="{link}">
    <img src="{umbracoFile}" alt="@nodeName" title="{@nodeName}" />
    </a>

    If this does not create the link then try adding <textarea><xsl:copy-of selec="." /></textarea> inside the for-each statement - this will return the XML for each image, which you can expect to see the structure of the XML and the element names.

    Hope this helps.

    /Jan

  • Nigel Wilson 945 posts 2077 karma points
    Dec 21, 2011 @ 19:38
    Nigel Wilson
    1

    Hi Alex

    Maybe try

    <xsl:attributename="href">
    <xsl:value-ofselect="umbraco.library:NiceUrl(current()/link)"/>
    </xsl:attribute>

    It would pay to do a check to see if a content node had been selected as a link too, otherwise you may get a XSLT error.

    Cheers

    Nigel

  • Alex Burr 77 posts 128 karma points
    Dec 21, 2011 @ 20:19
    Alex Burr
    0

    Thanks so much! Here's what I ended up putting inside my for-each loop:

    <xsl:choose>
      <xsl:when test="string(link)!=''">
        <a href="{umbraco.library:NiceUrl(current()/link)}">
          <img src="{umbracoFile}" alt="{@nodeName}" title="{@nodeName}" />
        </a>
      </xsl:when>
      <xsl:otherwise>
        <img src="{umbracoFile}" alt="{@nodeName}" title="{@nodeName}" />
      </xsl:otherwise>
    </xsl:choose>
Please Sign in or register to post replies

Write your reply to:

Draft