Copied to clipboard

Flag this post as spam?

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


  • Warren 30 posts 95 karma points
    May 16, 2013 @ 23:14
    Warren
    0

    How to Display Media Content in Templates using razor

    Hi

    I searched this site and could not seem to find a method of displaying media content in a template using razor.
    I found a way by using xslt, but I dont know a thing about xslt, and I am more fimiliar with razor.

    So here is a way that works for me using inline razor code.

    Note: "contentMediaImage" is the name of your Media Picker field.

     

     

                    <umbraco:Macro runat="server" Language="cshtml">              
    @inherits umbraco.MacroEngines.DynamicNodeContext
    @{
    if (Model.contentMediaImage != "")
    {
    var media = Library.MediaById(Model.contentMediaImage);
    <img src="@media.umbracoFile"  />
    }
    }
    </umbraco:Macro>


     

     

Please Sign in or register to post replies

Write your reply to:

Draft