Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Ben 4 posts 24 karma points
    Apr 30, 2011 @ 05:22
    Ben
    0

    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.


  • Eran Meir 401 posts 543 karma points
    Apr 30, 2011 @ 08:00
  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Apr 30, 2011 @ 08:03
    Jan Skovgaard
    1

    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

  • Ben 4 posts 24 karma points
    May 03, 2011 @ 04:35
    Ben
    0

    Yes, I'm using version 4.7. I will try to use the codeline you provided. Thanks Jan and Eran.

  • Ben 4 posts 24 karma points
    May 03, 2011 @ 05:29
    Ben
    0

    I have tried add the below statement into my template:

     

    <umbraco:Item runat="server" field="mediaItem" xslt="concat('&lt;img src=&quot;',umbraco.library:GetMedia({0}, true())/umbracoFile, '&quot; /&gt;')" xsltDisableEscaping="true"/>

     

    But the output is nothing. Did I do something wrong?

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    May 03, 2011 @ 22:36
    Jan Skovgaard
    0

    Hi Ben

    what version of Umbraco are you using?

    /Jan

  • Ben 4 posts 24 karma points
    May 04, 2011 @ 03:27
    Ben
    0

    umbraco v 4.7.0 (Assembly version: 1.0.4090.38017)

  • jason mitchell 11 posts 68 karma points
    May 06, 2011 @ 05:33
    jason mitchell
    0

    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) &gt; 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.

  • Pasang Tamang 258 posts 458 karma points
    May 06, 2011 @ 13:49
    Pasang Tamang
    0

    Hi Ben

    If your problem is not solved then try this one. 

    <img src="<umbraco:Item field='logoImage' xslt='umbraco.library:GetMedia({0},true())/umbracoFile' xsltDisableEscaping='true' runat='server' />"/>

    Above code is working for me and logoImage is the property with media picker type.

    Thanks

    Pnima

Please Sign in or register to post replies

Write your reply to:

Draft