Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
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
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
Hi Chriztian
Brilliant... absolutely brilliant!...
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.
Continue discussion
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:
...etc
Cheers
/Crawn
Hi Crawn,
There are lots of ways to so that better - here's one using a couple of XSLT templates:
/Chriztian
Hi Chriztian
Brilliant... absolutely brilliant!...
Cheers
/Crawn
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.