I've been sweating over this one for a day now and can't figure things out when trying to display an image from the Media Library. I've read many posts on this but nothing seems to work.
The below just puts the actual zsl script in the text area <textarea width="250" rows="10"> <xsl:value-of select="umbraco.library:GetMedia(1200,0)" /> </textarea>
The below does display the media ID OK <umbraco:Item field="testimage" runat="server" />
The below just shows image not found <img src="{umbraco.library:GetMedia(1200, false)/Image/umbracoFile}"/> and the actual source view of the HTML rendered is the same.
Any ideas what is going on.
I've granted all the correct permisisons on the site folders and is a clean install with Simple Starter Kit installed.
On another machine using an older version of Umbraco everything seems to work OK.
And the actual source of the rendered HTML which jsut shows the XSLT.Not sure where all the HTML headers and BODY is gone thoughI would think that the Master Page would include all that. I think I might jsut start again with a clean install.
Looks like you're trying to use XSLT directly within your template, afraid that's not going to work. To use XSLT, you would need to create a Macro for it first. (Take a look at this Umbraco.tv video about doing that).
If you just want to display the image, then try using this code snippet:
The logic here is that we use the Item control/tag to get the value of "testimage", which if exists will output the escapes HTML <img> tag before and after it ... the Xslt attribute is used to make the call to GetMedia (from the cache/database).
I know it might seem fairly complex - I'm sure you'll have questions, feel free to ask.
I installed Umbraco again to a new Database and IIS Website.
I've set up a Media PIcker on the Document Type In the template I've added the code to render the image, which still doesn't work even when in the content of the page I've selected the image????
Here's the template which does display the media ID but when trying to display the image nothing appears. All the fields have the full permissions but I'm think this version 4.7.1 is not working as I have used the exact same idea before in older versions with no problems.
version 4.7.1 GetMedia returns nothing
Version 4.7.1
IIS 7
OS:Windows 7 Professionsl
HI
I've been sweating over this one for a day now and can't figure things out when trying to display an image from the Media Library.
I've read many posts on this but nothing seems to work.
The below just puts the actual zsl script in the text area
<textarea width="250" rows="10">
<xsl:value-of select="umbraco.library:GetMedia(1200,0)" />
</textarea>
The below does display the media ID OK
<umbraco:Item field="testimage" runat="server" />
The below just shows image not found
<img src="{umbraco.library:GetMedia(1200, false)/Image/umbracoFile}"/> and the actual source view of the HTML rendered is the same.
Any ideas what is going on.
I've granted all the correct permisisons on the site folders and is a clean install with Simple Starter Kit installed.
On another machine using an older version of Umbraco everything seems to work OK.
Thanks
Allan
Hey Allan,
Welcome to the Umbraco forum!
Im not sure why you're having a problem but might be worth trying this solution from here
<xsl:variable name="mediaId" select="number($currentPage/testimage)" />
<xsl:if test="$mediaId > 0">
<xsl:variable name="mediaNode" select="umbraco.library:GetMedia($mediaId, 0)" />
<xsl:if test="$mediaNode/umbracoFile">
<img src="{$mediaNode/umbracoFile}" height="{umbracoHeight}" width="{umbracoWidth}" />
</xsl:if>
</xsl:if>
Sorry, missed the link http://blog.leekelleher.com/2010/08/11/how-to-use-umbraco-library-getmedia-in-xslt-for-umbraco-v4-5/
Rich
No joy...
Here's the actual template code.
<%@ Master Language="C#" MasterPageFile="~/umbraco/masterpages/default.master" AutoEventWireup="true" %>
<asp:Content ContentPlaceHolderID="ContentPlaceHolderDefault" runat="server">
<textarea width="250" rows="10">
<xsl:value-of select="umbraco.library:GetMedia(1200,0)" />
</textarea>
hello
<xsl:copy-of select="umbraco.library:GetMedia(1200, 'false')" />
<img src="{umbraco.library:GetMedia(1200, false)/Image/umbracoFile}"/>
<umbraco:Item field="testimage" runat="server" />
<umbraco:Item runat="server" field="testimage" xslt="umbraco.library:GetMedia({0}, true())/@nodeName" />
<xsl:variable name="mediaId" select="number($currentPage/testimage)" />
<xsl:if test="$mediaId > 0">
<xsl:variable name="mediaNode" select="umbraco.library:GetMedia($mediaId, 0)" />
<xsl:if test="$mediaNode/umbracoFile">
<img src="{$mediaNode/umbracoFile}" height="{umbracoHeight}" width="{umbracoWidth}" />
</xsl:if>
</xsl:if>
</asp:Content>
And the actual source of the rendered HTML which jsut shows the XSLT.Not sure where all the HTML headers and BODY is gone thoughI would think that the Master Page would include all that. I think I might jsut start again with a clean install.
<
textareawidth="250"rows
="10">
<xsl:value-ofselect="umbraco.library:GetMedia(1200,0)"/>
</
textarea
>
hello
<
xsl:copy-ofselect="umbraco.library:GetMedia(1200, 'false')"
/>
<
imgsrc
="{umbraco.library:GetMedia(1200, false)/Image/umbracoFile}"/>
1200
<
xsl:variablename="mediaId"select="number($currentPage/testimage)"
/>
<xsl:iftest="$mediaId > 0"><xsl:variablename="mediaNode"select="umbraco.library:GetMedia($mediaId, 0)"/><xsl:iftest="$mediaNode/umbracoFile"><imgsrc="{$mediaNode/umbracoFile}"height="{umbracoHeight}"width="{umbracoWidth}"/></xsl:if></xsl:if>
Hi Allan, welcome to Umbraco!
Looks like you're trying to use XSLT directly within your template, afraid that's not going to work. To use XSLT, you would need to create a Macro for it first. (Take a look at this Umbraco.tv video about doing that).
If you just want to display the image, then try using this code snippet:
The logic here is that we use the Item control/tag to get the value of "testimage", which if exists will output the escapes HTML <img> tag before and after it ... the Xslt attribute is used to make the call to GetMedia (from the cache/database).
I know it might seem fairly complex - I'm sure you'll have questions, feel free to ask.
Cheers, Lee.
Tried the adding the umbraco item in to a clean install and nothing showsnot even in the HTML source???
Hi Allan,
When you say clean install, how do you mean? I'm assuming that you have a document-type with the media picker, etc?
or could be an issue with the template? Would you might copy-n-pasting it here (again)?
Cheers, Lee.
I installed Umbraco again to a new Database and IIS Website.
I've set up a Media PIcker on the Document Type
In the template I've added the code to render the image, which still doesn't work even when in the content of the page I've selected the image????
Here's the template which does display the media ID but when trying to display the image nothing appears. All the fields have the full permissions but I'm think this version 4.7.1 is not working as I have used the exact same idea before in older versions with no problems.
<%@ Master Language="C#" MasterPageFile="~/umbraco/masterpages/default.master" AutoEventWireup="true" %>
<asp:Content ContentPlaceHolderID="ContentPlaceHolderDefault" runat="server">
<br/>
<umbraco:Item field="media" recursive="true" runat="server" />
<br/>
<umbraco:Item runat="server" Field="media" insertTextBefore="<img src='" insertTextAfter="' alt='image' />" Xslt="umbraco.library:GetMedia({0}, 0)/umbracoFile" />
</asp:Content>
Hi Allan,
I believe you need to add recursive="true" to your 2nd line, like this:
<umbraco:Item runat="server" Field="media" recursive="true" insertTextBefore="<img src='" insertTextAfter="' alt='image' />" Xslt="umbraco.library:GetMedia({0}, 0)/umbracoFile" />
Let us know how it goes!
Rich
Still no joy:-(...not feeling the love for Umbraco at the moment
Hey Allan,
Fear not, we'll definately get there.
Believe me what you are trying to achieve works!
There must be something we're missing so let's go from the start.
1) Is it possible to post a picture / screenshot of your content tree
2) Are you 100% sure you're using a Media Picker datatype for a property named 'media'
3) What Document Type is the 'media' property on
Rich
Rich
I'm happy to do a remote session if you want to give me your contact details.
No problem, Skype name sent
is working on a reply...