Copied to clipboard

Flag this post as spam?

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


  • Amir Khan 1282 posts 2739 karma points
    Feb 11, 2013 @ 17:53
    Amir Khan
    0

    Error when inserting <ul>

    I have this razor script which generates 2 levels of navigation from the current page. It seems to be working fine until I wrap the second foreach statement in a <ul>, then it throws an error saying the variable doesn't exist in the current context.

    Any ideas?

    @inherits umbraco.MacroEngines.DynamicNodeContext


    @* Ensure that the Current Page has children, where the property umbracoNaviHide is not True *@
    @if (Model.Parent.Children.Where("Visible").Any())
    {
    <nav>
    <ul>
    @* For each child page under the root node, where the property umbracoNaviHide is not True *@
    @foreach (var childPage in Model.Parent.Children.Where("Visible"))
    {
    <li>
    <a href="@childPage.Url">
    @if(@childPage.HasProperty("navigationDisplayName") && @childPage.GetProperty("navigationDisplayName").Value != String.Empty)
    {
    @childPage.navigationDisplayName;
    }
    else {
    @childPage.Name;
    }
    </a>
    @if (childPage.Children.Where("Visible").Count() > 0)
    {
    <ul>
    foreach (var childChildPage in childPage.Children.Where("Visible"))
    {
    <li>
    <a href="@childChildPage.Url">
    @if(@childChildPage.HasProperty("navigationDisplayName") && @childChildPage.GetProperty("navigationDisplayName").Value != String.Empty)
    {
    @childChildPage.navigationDisplayName;
    }
    else {
    @childChildPage.Name;
    }
    </a>
    </li>
    }
    </ul>
    }
    </li>
    }
    </ul>
    </nav>
    }

  • Fuji Kusaka 2203 posts 4220 karma points
    Feb 11, 2013 @ 18:09
    Fuji Kusaka
    0

    Hi Amir,

    You need to add the @ sign before your foreach loop

    @foreach (var childChildPage in childPage.Children.Where("Visible")
  • Fuji Kusaka 2203 posts 4220 karma points
    Feb 11, 2013 @ 19:06
    Fuji Kusaka
    100

    Hi Amir,

    You need to add the @ sign before your foreach loop

    @foreach (var childChildPage in childPage.Children.Where("Visible")
  • Amir Khan 1282 posts 2739 karma points
    Feb 11, 2013 @ 19:08
    Amir Khan
    0

    Thanks Fuji!

Please Sign in or register to post replies

Write your reply to:

Draft