Creating a loop of child nodes and fields from fixed parent node
Hi Guys,
I'm new to razor and am struggling with this partial based macro. Trying to include an image in which is selected on the child node via a media picker with the attribute ID of sliderImage. I can get the image node number but cant convert it to the its url.
Hmmm... I'd check the macro property 'startNodeID' exists and has the correct alias. I'd also check the 'sliderImage' property exists and has the correct alias as well. Do you know which line the error is appearing on?
Creating a loop of child nodes and fields from fixed parent node
Hi Guys,
I'm new to razor and am struggling with this partial based macro. Trying to include an image in which is selected on the child node via a media picker with the attribute ID of sliderImage. I can get the image node number but cant convert it to the its url.
@inherits Umbraco.Web.Macros.PartialViewMacroPage
@if (Model.MacroParameters["startNodeID"] != null)
{
@* Get the start node as a dynamic node *@
var startNode = Umbraco.Content(Model.MacroParameters["startNodeID"]);
if (startNode.Children.Where("Visible").Any())
{
foreach (var page in startNode.Children.Where("Visible"))
{
@:<section id="@page.Name" class="homepage-section wait-for-load">
@:<div class="title-wrap" style="background-image:@page.sliderImage">
@:<div class="title-content">
@:<h2><a href="@page.Url"></a>@page.Name</h2>
@:<a href="@page.Url" class="more-link">@page.Name</a>
@:</div>
@:</div>
@:</section>
}
}
}
Hi Chris,
You'll want to convert the media ID to a TypedMedia instance as follows:
Thanks, Dan.
Hi Dan,
I actually came across a few example like that, have tried but am getting the following:
Error loading Partial View script (file: ~/Views/MacroPartials/splash-pages.cshtml)
I must be missing something very simple somewhere....
Chris
The actual error logs state:
Error loading partial view macro (View: ~/Views/MacroPartials/splash-pages.cshtml). Exception: Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: Cannot perform runtime binding on a null reference
at CallSite.Target(Closure , CallSite , Object )
Hmmm... I'd check the macro property 'startNodeID' exists and has the correct alias. I'd also check the 'sliderImage' property exists and has the correct alias as well. Do you know which line the error is appearing on?
Thanks, Dan.
Not sure... I had to get the site delivered. Resorted to xlst based macro. I need to get my head around razor more.
It seem all correct.. Was running the latest version, did i need ucomponents installed? Not sure if its supported on 7.x.x
uComponents only works with v6 and below. nuPickers is a good v7 alternative to some of the data types present in uComponents.
Thanks, Dan.
is working on a reply...