Copied to clipboard

Flag this post as spam?

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


  • Amby 30 posts 50 karma points
    Nov 29, 2011 @ 14:18
    Amby
    0

    Error loading razor script - inline razor

    Hi,

    I need to access parent image property from a child node and if it does not exist use the child image using inline razor.

          <umbraco:Macro runat="server" language="cshtml">
            @using umbraco.MacroEngines;
            @if(@Model.Parent.headerImage.GetType() == typeof(DynamicNull))
            {
              <img src='@Model.headerImage'/>   
            }
           else
            {
              <img src='@Model.Parent.headerImage'/>
            }

          </umbraco:Macro>

    isn't this possible??

    Regards,

    Ambika

  • Matt Barlow | jacker.io 164 posts 740 karma points c-trib
    Dec 01, 2011 @ 12:41
    Matt Barlow | jacker.io
    0

    Hey,
    Am assuming you have the same script in both the parent and child and you are using the native mediapicker datatype.
    I checked this and it works:

    <
    umbraco:Macro runat="server" language="cshtml">
    @using umbraco.MacroEngines;
    @helper renderImage(DynamicNode node, Boolean isParent)
          {
          if(@node.GetPropertyValue("headerImage") != string.Empty){
          var mediaItem = Model.MediaById(@node.GetPropertyValue("headerImage"));
          @:<img src="@mediaItem.Url" alt="@mediaItem.Name" >
          }else
            {
             @renderImage(Model, false);
            }
    }
         
    @if (@Model.Parent.headerImage.GetType() != typeof(DynamicNull))
    {
          @renderImage(Model.Parent, true);
    }else {
          @renderImage(Model, false);
    }
       
    umbraco:Macro>


  • Amby 30 posts 50 karma points
    Dec 07, 2011 @ 11:01
    Amby
    0

    Thank for the reply. I get errors while adding @Model to the script.

       <umbraco:Macro runat="server" language="cshtml">
          @{var bodyText=@Model.HasProperty("headerImage");
          }
        </umbraco:Macro>

    Do I have to add any namespace?

    Regards,

    Ambika

  • Matt Barlow | jacker.io 164 posts 740 karma points c-trib
    Dec 07, 2011 @ 11:20
    Matt Barlow | jacker.io
    0

    That script you wrote works for me, what is the error you are getting?

  • Amby 30 posts 50 karma points
    Dec 07, 2011 @ 22:44
    Amby
    0

    It works now. thanks Matt.

    Regards,

    Ambika

     

  • 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