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
Hello Umbraco Community,
I've writen a XSLT to display all my single News Items.After that i inserted it to my template.
This XSLT should display the single Items like that:-Header-Date-PictureMy problem is that the picture displays the id instead of the picture.How can I fix this?
I am using Umbraco 7.1.8
This is my XSLT:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp " "> ]> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxml="urn:schemas-microsoft-com:xslt" xmlns:umbraco.library="urn:umbraco.library" xmlns:Examine="urn:Examine" exclude-result-prefixes="msxml umbraco.library Examine "> <xsl:output method="xml" omit-xml-declaration="yes"/> <xsl:param name="currentPage"/> <xsl:template match="/"> <!-- The fun starts here --> <ul> <xsl:for-each select="$currentPage/* [@isDoc and string(umbracoNaviHide) != '1']"> <a> <h2><a href="{umbraco.library:NiceUrl(@id)}"> <xsl:value-of select="@nodeName"/> </a></h2> <small class="meta">Posted: <xsl:value-of select="umbraco.library:LongDate(@updateDate, true(), ' - ')"/></small><br/> <p class="introduction"> <xsl:value-of select="umbraco.library:ReplaceLineBreaks(introduction)"/> </p> <xsl:value-of select="newspicture"/> </a> </xsl:for-each> </ul> </xsl:template> </xsl:stylesheet>
Thank you very much.
Sincerely David :)
Hi David
That's because you need to find the image based on the id. You can see how it's done using XSLT here http://our.umbraco.org/wiki/reference/umbracolibrary/getmedia
So where you in your code currently have <xsl:value-of select="newspicture"/>
<xsl:value-of select="newspicture"/>
You need this
<xsl:variable name="media" select="umbraco.library:GetMedia($currentPage/newspicture, 0)" /> <xsl:if test="$media"> <xsl:variable name="url" select="$media/umbracoFile" /> <xsl:variable name="width" select="$media/umbracoWidth" /> <xsl:variable name="height" select="$media/umbracoHeight" /> <img src="{$url}" width="{$width}" height="{$height}" /> </xsl:if>
Hope this makes sense :)
Cheers, Jan
Jan beat me to it! His post is clearer!
Hello Jan,
thank you for your fast answer.I've just replaced
with
<xsl:variablename="media"select="umbraco.library:GetMedia($currentPage/newspicture, 0)"/> <xsl:iftest="$media"> <xsl:variablename="url"select="$media/umbracoFile"/> <xsl:variablename="width"select="$media/umbracoWidth"/> <xsl:variablename="height"select="$media/umbracoHeight"/> <imgsrc="{$url}"width="{$width}"height="{$height}"/> </xsl:if>
and it show the following error.
What is wrong now?I don't get it.Thank you in advance.
Seems like your <xsl:if test> is wrong...it's collapsed into <xsl:iftest>
<xsl:if test>
<xsl:iftest>
/Jan
Hi David,
What if you do something like this:
<xsl:if test="./newspicture !=''"> <xsl:variable name="media" select="umbraco.library:GetMedia(./newspicture, 0)" /> <xsl:variable name="url" select="$media/umbracoFile" /> <xsl:variable name="width" select="$media/umbracoWidth" /> <xsl:variable name="height" select="$media/umbracoHeight" /> <img src="{$url}" width="{$width}" height="{$height}" /> </xsl:if>
Hope this helps,
/Dennis
Thank you very much, Dennis !This worked for me !!
Ah yes, the classical test to see if we get an id at all :)
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
XSLT displays picture ID instead of the picture.
Hello Umbraco Community,
I've writen a XSLT to display all my single News Items.
After that i inserted it to my template.
This XSLT should display the single Items like that:
-Header
-Date
-Picture
My problem is that the picture displays the id instead of the picture.
How can I fix this?
I am using Umbraco 7.1.8
This is my XSLT:
Thank you very much.
Sincerely David :)
Hi David
That's because you need to find the image based on the id. You can see how it's done using XSLT here http://our.umbraco.org/wiki/reference/umbracolibrary/getmedia
So where you in your code currently have
<xsl:value-of select="newspicture"/>
You need this
Hope this makes sense :)
Cheers, Jan
Jan beat me to it! His post is clearer!
Hello Jan,
thank you for your fast answer.
I've just replaced
<xsl:value-of select="newspicture"/>
with
and it show the following error.
What is wrong now?
I don't get it.
Thank you in advance.
Sincerely David :)
Hi David
Seems like your
<xsl:if test>
is wrong...it's collapsed into<xsl:iftest>
/Jan
Hi David,
What if you do something like this:
Hope this helps,
/Dennis
Thank you very much, Dennis !
This worked for me !!
Ah yes, the classical test to see if we get an id at all :)
/Jan
is working on a reply...