Copied to clipboard

Flag this post as spam?

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


  • Dibs 202 posts 991 karma points
    Sep 30, 2015 @ 13:19
    Dibs
    0

    render image if true/false macro Parameter checked

    Dear Umbraco Team

    Trying to render images if boolean field in macro is checked. with code below i get "Error loading Partial View script. any Ideas ?

    @if(Model.MacroParameters["bool"]){
        @{ var media = Model.MacroParameters["Image"];}
        @if(media !=null){
            var image = Umbraco.TypedMedia(media);
            <img class="img-responsive" src="@image.GetPropertyValue("umbracoFile")" alt="@image.GetPropertyValue("Name")" />
        }   
    }
    

    Thanks Dibs

  • Benas Brazdziunas 34 posts 156 karma points c-trib
    Oct 01, 2015 @ 14:01
    Benas Brazdziunas
    1

    Try to parse Model.MacroParameters["bool"] to to string and compare == "1"

    fixed code:

    @{
        if (Model.MacroParameters["bool"].ToString() == "1")
        {
            var media = Model.MacroParameters["Image"];
            if (media != null)
            {
                var image = Umbraco.TypedMedia(media);
                <img class="img-responsive" src="@image.GetPropertyValue("umbracoFile")" alt="@image.GetPropertyValue("Name")" />
            }
        }
    }  
    
  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies