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>
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
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>
Thank for the reply. I get errors while adding @Model to the script.
<umbraco:Macro runat="server" language="cshtml">
@{var [email protected]("headerImage");
}
</umbraco:Macro>
Do I have to add any namespace?
Regards,
Ambika
That script you wrote works for me, what is the error you are getting?
It works now. thanks Matt.
Regards,
Ambika
is working on a reply...