|
|
Rank: Newbie
Joined: 3/25/2008 Posts: 11
|
Hi,
I have made a document type where an image can be selected with the Media Picker, but I get an xslt-error on the published page if an image has not been selected.
How do I check if an image has been selected?
|
|
 Rank: Addict
Joined: 7/19/2006 Posts: 738 Location: Århus, Denmark
|
There are a few ways to do this. How do you get the image property in your XSLT? Is it passed via. a macro parameter, or do your get it from the $currentNode parameter? What you probably want to do is use either an xsl:if or a xsl:choose, depending on what should happen if there is no image chosen. Could you describe what you need to do if no image has been selected? Should it just not be displayed, or should it inherit a value from the parent node, or should it default to some hardcoded image?
|
|
Rank: Newbie
Joined: 3/25/2008 Posts: 11
|
Hi Morten
I use a macro like this i found here in the forum
<xsl:template match="/">
<img src="{umbraco.library:GetMedia($currentPage/data[@alias='ProfileImage'], 'false')/data [@alias = 'umbracoFile']}"/>
</xsl:template>
In case no image is selected, nothing will be displayed.
Hope this information is enough :)
|
|
 Rank: Newbie
Joined: 3/29/2008 Posts: 13 Location: NC
|
Code that I use looks something like this
<xsl:for-each select="$currentPage/node [string(data [@alias='umbracoNaviHide']) != '1']"> <xsl:choose> <xsl:when test="string-length(data [@alias='TeaserImage'])"> <div class="TeaserImage"> <img width='150px' src="{umbraco.library:GetMedia(data [@alias = 'TeaserImage'],true)/data [@alias = 'umbracoFile']}" /> </xsl:when> <xsl:otherwise> <img width='150px' src="/data/assests/imgnotfound.png" /> </xsl:otherwise> </xsl:choose>
Hope that helps,
Hal
|
|
 Rank: Addict
Joined: 7/19/2006 Posts: 738 Location: Århus, Denmark
|
Mikkel, in your case, I think you should use something like this: Code: <xsl:template match="/"> <xsl:if test="$currentPage/data[@alias='ProfileImage'] != ''"> <img src="{umbraco.library:GetMedia($currentPage/data[@alias='ProfileImage'], 'false')/data [@alias = 'umbracoFile']}"/> </xsl:if> </xsl:template>
I think that the media picker returns an empty string if nothing is selected, så that should do the job. It might return a "0", but then you just change your xsl:if to handle that instead. If you want to see what exactly your mediapicker returns, then use Code: <xsl:copy-of select="$currentPage/data[@alias='ProfileImage']"/>
|
|
Rank: Newbie
Joined: 3/25/2008 Posts: 11
|
Morten...it worked just fine!
Thx :)
|
|
|
Guest |