Copied to clipboard

Flag this post as spam?

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


  • Craig Pickles 5 posts 25 karma points
    Jul 09, 2010 @ 16:14
    Craig Pickles
    0

    Displaying images in Template from Media Picker

    Hi Guys, 

    I'm trying to setup a simple site during evaluating Umbraco.  I have a template with a "Media Picker" Content Type and would like to display the image that the user has chosen in the template.

    If I put the following code in the template: <umbraco:Item runat="server" field="imagecontent"/>

    Then it displays the ID of the image (I'm assuming). I've been trying to read up on the various ways of doing it and most are centered around creating an external XSLT file etc. or a macro.  Is it not possible just to put something simple inline into the template to display the image?

    I've looked around and it appears that there should be a solution which is as follows:

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

    But it just returns: <img src="" />

    Is there a quick and easy way or do I really have to create a seperate xslt file for every image I want to put in the template?

    Any help would be appreciated.

    Thanks, Craig


  • dandrayne 1138 posts 2262 karma points
    Jul 09, 2010 @ 16:52
    dandrayne
    0

    Hi Craig

    Are you using 4.5?  If so the xml schema is a little different - try this

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

    Dan

  • Craig Pickles 5 posts 25 karma points
    Jul 09, 2010 @ 17:02
    Craig Pickles
    0

    YOU BEAUTY!

    Thanks Dan! :) That was it, all the documentation I was looking at was for 3.0 by the looks of it! :)

    Cheers Bud! :)

    Craig

     

  • dan 29 posts 53 karma points
    Jul 09, 2010 @ 21:32
    dan
    0

    When inserting an umbraco page field, there is also an option to add tag before and after. I know it works in version 4. I don't know if it's different in 4.5.

    It will look something like this.

    <umbraco:Item field="Image" insertTextBefore="&lt;img src=&quot;" insertTextAfter="&quot;&gt;" runat="server"></umbraco:Item>

     

    Dan

    danielcruger.com

Please Sign in or register to post replies

Write your reply to:

Draft