Copied to clipboard

Flag this post as spam?

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


  • Brad 94 posts 151 karma points
    Feb 26, 2013 @ 06:03
    Brad
    0

    Displaying an image added as a media item

    I'm using Umbraco 6 on a project.

    I used the Media area to upload an image for use on a page.

    Next I created a document type and specified one of the fields to be a Media Picker.

    When I created one of these pages I am able to use the media picker to pick the image I want to display.

    The problem starts in the template.

    If I just put this element on the page

    <umbraco:Item field="titleBanner" runat="server" />

    ... the result is some 4 digit value. I assume some sort of ID for this item. ie: Useless..

    I can't work out how to display the selected image in my template. I have been on the forums and searching google for the last few hour and none of the 'solutions' with their 'inline-xlst', worked. 

    The last one I tried... This one...

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

    ... returned

    <img src="" />

    I need help.

    I would have thought that by version 6 of Umbraco, adding an media image to a template for display on a page is a snap. Maybe it is. I just don't know how to do it.

     

     

  • Owen 123 posts 246 karma points
    Feb 26, 2013 @ 06:33
    Owen
    1

    By razor code:

    <img src="@Umbraco.TypeMedia(Model.Content.GetPropertyValue("titleBanner")).GetPropertyValue("umbracoFile")"/>

  • Charles Afford 1163 posts 1709 karma points
    Feb 26, 2013 @ 22:30
    Charles Afford
    0

    Thanks for this snippit of code :)

  • Brad 94 posts 151 karma points
    Feb 26, 2013 @ 23:36
    Brad
    0

    Owen

    I dropped your line of code into my template and ran the site.

    No image appeared.

    What gets output to the browser when I look at the source code of the page is...

    <img src="@Umbraco.TypeMedia(Model.Content.GetPropertyValue("titleBanner")).GetPropertyValue("umbracoFile")"/>

    Looks to me that my template is no parsing the razor syntax.. Is that possible?

  • Owen 123 posts 246 karma points
    Feb 26, 2013 @ 23:49
    Owen
    0

    To Brad, Are you in MVC mode? You can't use it in WebForm mode directly.

    Have a try:

    <umbraco:Macro runat="server" language="cshtml">

    <img src="@Umbraco.TypeMedia(Model.Content.GetPropertyValue("titleBanner")).GetPropertyValue("umbracoFile")"/>

    </umbraco:Macro>

    Or use a macro instead

  • Brad 94 posts 151 karma points
    Feb 26, 2013 @ 23:55
    Brad
    0

    Owen

    You might be on to something.. MVC Mode?

    When I tried your latest code bit, this was output to the browser

    <div style="border: 1px solid #990000">Error loading Razor Script br/>div>

     Update:

    Ok. After a bit of reading I know about MVC mode.. I don't have time right not to convert the site to MVC so I can run this one line to display an image.  

    So for now,  how do I do this without Razor?

     

     

     

     

     

Please Sign in or register to post replies

Write your reply to:

Draft