Copied to clipboard

Flag this post as spam?

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


  • Tarunjit 103 posts 146 karma points
    Feb 10, 2015 @ 12:33
    Tarunjit
    0

    Adding Images To Templates From Media Folder

    Hi All,

    Can anyone please let us know the technique for uploading images to the templates from image already uploaded in Media folder.

    Here is the technique we have applied so far :-

    • Uploaded image named “logo” on Media folder
    • Manually added code snippet “” in template but it is not rendering image on the page.

    Can anyone please help us on this?

    Regards

    Tarunjit Singh

     

     

     

     

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Feb 10, 2015 @ 12:40
    Jan Skovgaard
    1

    Hi Trunjit

    You should use Razor to render the image - I don't think the above snippet works in v7. Does it return anything? A path or an id?

    Otherwise you should be able to use Razor for this like this

    var mediaId = Model.Umbraco.Field("yourimageproperty").ToString();
    <img src="@Model.Umbraco.TypedMedia(mediaId).Url" alt="" />
    

    You can read more about it here https://our.umbraco.org/documentation/Reference/Templating/Mvc/querying

    I hope this helps.

    /Jan

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Feb 10, 2015 @ 12:49
    Dennis Aaen
    1

    Hi Trunjit,

    If you are using the media picker to selected the image in Umbraco backoffice, then you sould be good with this code.

    @if (CurrentPage.HasValue("yourimageproperty")){ 
        var dynamicMediaItem = Umbraco.Media(CurrentPage.yourimageproperty);
        <img src="@dynamicMediaItem.umbracoFile" alt="@dynamicMediaItem.Name"/>
    }

    See the documentation here. https://our.umbraco.org/documentation/Using-Umbraco/Backoffice-Overview/Property-Editors/Built-in-Property-Editors/Media-Picker

    Hope this helps,

    /Dennis

  • Tarunjit 103 posts 146 karma points
    Feb 10, 2015 @ 12:51
    Tarunjit
    0

    Hi Jan,

    Thanks for your reply.

    But this doesn't seem to work. We have used following code snippet

    var mediaId = Model.Umbraco.Field("logo").ToString();

    <img src="@Model.Umbraco.TypedMedia(mediaId).Url" alt="" />

    Just for your informatio we are using Umbraco 7.2.1 version and also WebForms rendering technique and not the MVC.

    Regards

    Tarunjit Singh

     

  • Tarunjit 103 posts 146 karma points
    Feb 10, 2015 @ 12:55
    Tarunjit
    0

    Hi Dennis,

    Thanks for the help.

    Just for your informatio we are using Umbraco 7.2.1 version and also WebForms rendering technique and not the MVC. My question to you is will the code snippet share by you will work fine in my case?

    Regards

    Tarunjit Singh

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Feb 10, 2015 @ 12:59
    Dennis Aaen
    0

    Hi Tarunjit,

    Yes as far as I remember you can also using Razor directly into your template when you are running in WebForm mode. Otherwise you can create a partial view macro, and insert this there where you want the logo to appear

    Hope this helps,

    /Dennis

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Feb 10, 2015 @ 13:02
    Jan Skovgaard
    1

    Hi guys

    When using webforms you need to create a partial view macro, which can be inserted in the template. You won't be able to execute the Razor code directly in the masterpage as you could with MVC.

    /Jan

  • Tarunjit 103 posts 146 karma points
    Feb 10, 2015 @ 13:07
    Tarunjit
    0

    Hi Dennis,

    We have just tried your code snippet and it is not working. It is simply displaying the code snippet which we have written in template. 

    @if (CurrentPage.HasValue("logo")){ 

        var dynamicMediaItem = Umbraco.Media(CurrentPage.yourimageproperty); 

        <img src="@dynamicMediaItem.umbracoFile" alt="@dynamicMediaItem.Name"/> 

     

    }

    As far as creation of partial view macro is concerened i am not at all ware of MVC coding. Is there some other technique like creating a user control and embeding some code in the user control to render this image? If yes please share that code snippet?

    Regards

    Tarunjit Singh


  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Feb 10, 2015 @ 13:14
    Dennis Aaen
    1

    Hi Tarunjit,

    Create a partial view macro and insert the macro into the template. Try to see this documentation, on how to create partial view macro. https://our.umbraco.org/documentation/Reference/Templating/Macros/Partial-View-Macros/ and if you have access to the Umbraco TV take a look here: http://umbraco.tv/videos/umbraco-v7/implementor/working-with-umbraco-data/macros/creating-a-macro/

    Hope this helps,

    /Dennis

     

Please Sign in or register to post replies

Write your reply to:

Draft