Hi, I have a node referenced in my flow which I am capturing via a contentpicker called 'contentSource' I have a property in that called 'contentSource'.
I am then trying to display that image on my page. However, when I save the following code, I get the error message displayed at the bottom.
Yes - the reason you're getting that error is because Umbraco will do some checking on the XSLT to see if it's at least a "valid" file before saving it, so it will execute a transform where it will use "Content" as $currentPage. That node doesn't have a contentSource property and since the XSLT assumes that one is there *and* that it has a valid media ID, the call to GetMedia() fails. You can safeguard against this with a simple if instruction:
Media library issues
Hi, I have a node referenced in my flow which I am capturing via a contentpicker called 'contentSource' I have a property in that called 'contentSource'.
I am then trying to display that image on my page. However, when I save the following code, I get the error message displayed at the bottom.
Hope you can help, many thanks.
<xsl:param name="currentPage"/>
<xsl:variable name="source" select="$currentPage/contentSource"/>
<xsl:variable name="media" select="umbraco.library:GetMedia(umbraco.library:GetXmlNodeById($source)/topImage, 0)" />
<!-- The fun starts here -->
<xsl:if test="$media">
<img class="topImage" src="{$media/umbracoFile}" alt="{$media/umbracoTag}" width="{$media/umbracoWidth}" height="{$media/umbracoHeight}"/>
</xsl:if>
By the way, if I skip testing the image actually displays!?
Hi Lee,
Yes - the reason you're getting that error is because Umbraco will do some checking on the XSLT to see if it's at least a "valid" file before saving it, so it will execute a transform where it will use "Content" as $currentPage. That node doesn't have a contentSource property and since the XSLT assumes that one is there *and* that it has a valid media ID, the call to GetMedia() fails. You can safeguard against this with a simple if instruction:
/Chriztian
Perfect... works a treat. Thanks Chriztian!
is working on a reply...