In order to fetch the image you need to create either inline xslt directly in the template or create a macro based on either razor or XSLT to get the image.
If you create a XSLT based macro you need to use the GetMedia extension, which is also being used in the inline example above. There is a good explanation and code sample on how to use it in this wiki entry here: http://our.umbraco.org/wiki/reference/umbracolibrary/getmedia
Be aware to use the correct sample with the new XML schema since I'm guessing you are using version 4.7, right? :-)
I typed this from memory, so don't expect it to work without some fiddling. Basically all it does is return the location of the media ID you pass it. This is also, most likely, complete overkill for this... but it will work.
How can I get the media path in my template?
I'm newbie in umbraco. I have just known how to add image in template like the following:
<img src=' <umbraco:Item field="umbracoFile" nodeID="1076" runat="server"></umbraco:Item> ' />
but anyway, how can get the image path in template?
I have tried to create a new media which type is folder. And I move the image media to that folder. I found the id in my created folder.
But the below statement was returned
Object reference not set to an instance of an object.
<umbraco:Item field="umbracoFile" nodeID="<my folder id>" runat="server"></umbraco:Item>
Please help.
hey, check out this http://our.umbraco.org/forum/using/ui-questions/19399-render-image-from-media-using-media-picker-in-Umbraco-452
Hi Ben
Welcome to the Umbraco community :-)
In order to fetch the image you need to create either inline xslt directly in the template or create a macro based on either razor or XSLT to get the image.
By using inline XSLT you should be able to use the codeline, provided in this blogpost: http://raahede.com/blog/2010/10/03/inline-xslt-in-umbraco-templates.aspx
If you create a XSLT based macro you need to use the GetMedia extension, which is also being used in the inline example above. There is a good explanation and code sample on how to use it in this wiki entry here: http://our.umbraco.org/wiki/reference/umbracolibrary/getmedia
Be aware to use the correct sample with the new XML schema since I'm guessing you are using version 4.7, right? :-)
Hope this makes sense.
/Jan
Yes, I'm using version 4.7. I will try to use the codeline you provided. Thanks Jan and Eran.
I have tried add the below statement into my template:
<umbraco:Item runat="server" field="mediaItem" xslt="concat('<img src="',umbraco.library:GetMedia({0}, true())/umbracoFile, '" />')" xsltDisableEscaping="true"/>
But the output is nothing. Did I do something wrong?
Hi Ben
what version of Umbraco are you using?
/Jan
umbraco v 4.7.0 (Assembly version: 1.0.4090.38017)
The only way I know of is to create a XSLT macro that you basically feed it the nodeId (paramId) as a parameter:
<xsl:variable name="paramId" select="/macro/nodeId" />
<xsl:test if="string-length($paramId) > 0">
<xsl:value-of select="umbraco.library:GetMedia($paramId, 0)/data [@alias = 'umbracoFile']"/>
</xsl:test>
I typed this from memory, so don't expect it to work without some fiddling. Basically all it does is return the location of the media ID you pass it. This is also, most likely, complete overkill for this... but it will work.
Hi Ben
If your problem is not solved then try this one.
Above code is working for me and logoImage is the property with media picker type.
Thanks
Pnima
is working on a reply...