Why doesnt something like this work? theres nothing wrong with the way the variabel is created neither is there something wrong with the IF but if i put the if around the variabel to check if theres any data i get a error.
you little code snippet is perfectly valid - but node the scope of the variable. Your "prodImg1" variable is only visible inside the if-element, and thus cannot be referenced outside the <xsl:if>...</xsl:if>.
Well the reason for decaring the variable is that im going to use this filepath in a couple of places and do the same thing with about 4 more files. So having a variable instead woud make my code more readable. But i guess im just gonna have to get media on all the places then.
Shoudnt it be possible to give a variable null in value if the alias has no data? so i can create these and then check if the variable is null or not and create it then?
Why cant i do a if check around creating a variabel to see if there is any data.
<xsl:if test="string($currentPage/data[@alias='prodImg1'])!=''" >
<xsl:variable name="prodImg1" select="umbraco.library:GetMedia($currentPage/data [@alias='prodImg1'], 'false')/data [@alias = 'umbracoFile']" />
</xsl:if>
Why doesnt something like this work? theres nothing wrong with the way the variabel is created neither is there something wrong with the IF but if i put the if around the variabel to check if theres any data i get a error.
Hi Johan,
you little code snippet is perfectly valid - but node the scope of the variable. Your "prodImg1" variable is only visible inside the if-element, and thus cannot be referenced outside the <xsl:if>...</xsl:if>.
>Tommy
Hi Johan,
Why would you create this variable if you're after the filename only? Can't you just use it as is, without declaring the variable first?
(it's not an answer to your question tho...)
Cheers,
/Dirk
Ah ofc Tommy thx.
Well the reason for decaring the variable is that im going to use this filepath in a couple of places and do the same thing with about 4 more files. So having a variable instead woud make my code more readable. But i guess im just gonna have to get media on all the places then.
Shoudnt it be possible to give a variable null in value if the alias has no data? so i can create these and then check if the variable is null or not and create it then?
You ncan nest the if inside you variable, something like this:
<xsl:variable name="prodImg1">
<xsl:choose>
<xsl:when test="string($currentPage/data[@alias='prodImg1'])!=''">
<xsl:value-of select="umbraco.library:GetMedia($currentPage/data [@alias='prodImg1'], 'false')/data [@alias = 'umbracoFile']" />
</xsl:when>
<xsl:otherwise>
...
</xsl:otherwise>
<xsl:choose>
</xsl:variable>
>Tommy
Oh, works great. Thanks.
is working on a reply...