Copied to clipboard

Flag this post as spam?

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


  • Bent Holz 100 posts 273 karma points
    Mar 26, 2014 @ 14:43
    Bent Holz
    0

    List media picker pictures

    I'm trying to list 5 pictures via XSLT from values on my document type, this all works fine, but there must be an easier way...

    ...or could/should i just do this on the template? ...and how?

    What i have now is this:

    <div id="Images">
    <xsl:variable name="mediaId1" select="number($currentPage/itemPic1)" />
    <xsl:if test="$mediaId1 > 0">
    <xsl:variable name="mediaNode1" select="umbraco.library:GetMedia($mediaId1, 0)" />
    <xsl:if test="$mediaNode1/umbracoFile">
    <a href="{$mediaNode1/umbracoFile}" title="{$mediaNode1/umbracoFile}">
    <img src="{$mediaNode1/umbracoFile}" border="0" alt="{@nodeName}" />
    </a>
    </xsl:if>
    </xsl:if>
    <xsl:variable name="mediaId2" select="number($currentPage/itemPic2)" />
    <xsl:if test="$mediaId2 > 0">
    <xsl:variable name="mediaNode2" select="umbraco.library:GetMedia($mediaId2, 0)" />
    <xsl:if test="$mediaNode2/umbracoFile">
    <a href="{$mediaNode2/umbracoFile}" title="{$mediaNode2/umbracoFile}">
    <img src="{$mediaNode2/umbracoFile}" border="0" alt="{@nodeName}" />
    </a>
    </xsl:if>
    </xsl:if>

    ...etc

    Cheers

    /Crawn

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 7x admin c-trib
    Mar 26, 2014 @ 14:53
    Chriztian Steinmeier
    100

    Hi Crawn,

    There are lots of ways to so that better - here's one using a couple of XSLT templates:

    <?xml version="1.0" encoding="utf-8" ?>
    <xsl:stylesheet
        version="1.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:umbraco.library="urn:umbraco.library"
        exclude-result-prefixes="umbraco.library"
    >
    
        <xsl:output method="html" indent="yes" omit-xml-declaration="yes" />
    
        <xsl:param name="currentPage" />
        <xsl:variable name="siteRoot" select="$currentPage/ancestor-or-self::*[@level = 1]" />
    
        <xsl:template match="/">
            <div id="Images">
                <!-- Process all `itemPicN` properties that have a value stored -->
                <xsl:apply-templates select="$currentPage/*[starts-with(name(), 'itemPic')][normalize-space()]" mode="image" />
            </div>
        </xsl:template>
    
        <!-- Catch-all for the itemPicN properties -->
        <xsl:template match="*" mode="image">
            <xsl:variable name="mediaNode" select="umbraco.library:GetMedia(., false())" />
            <xsl:if test="not($mediaNode[error])">
                <xsl:apply-templates select="$mediaNode" />
            </xsl:if>
        </xsl:template>
    
        <!-- Template for an Image -->
        <xsl:template match="Image">
            <a href="{umbracoFile}" title="{umbracoFile}">
                <img src="{umbracoFile}" border="0" alt="{@nodeName}" />
            </a>
        </xsl:template>
    
        <!-- Example of another media type -->
        <xsl:template match="PDFfile">
            <a href="{umbracoFile}" type="application/pdf"><xsl:value-of select="@nodeName" /> (PDF)</a>
        </xsl:template>
    
    </xsl:stylesheet>
    

    /Chriztian

  • Bent Holz 100 posts 273 karma points
    Mar 26, 2014 @ 15:38
    Bent Holz
    0

    Hi Chriztian

    Brilliant... absolutely brilliant!...

    Cheers

    /Crawn

Please Sign in or register to post replies

Write your reply to:

Draft