Copied to clipboard

Flag this post as spam?

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


  • Marc 2 posts 22 karma points
    Apr 10, 2015 @ 11:04
    Marc
    0

    Nested Menu

    Hi - I'm new to this forum. Glad to be apart of the community!

    My question is related to Umbraco 4 development, I don't know if this is the right forum node to post in?

    We want to house a menu system of a parents decendant in our children pages - if that makes sense?

    Current structure of the section I'm working in: 

    - Page One (Main Page)
    - List of menu items (folder) -
    - Menu item 1 (element option)
    - Menu item 2 (element option)
    - Menu item 3 (element option)
    - Sub Page 1 (page)
    - Sub Page 2 (page)

    At the moment we're able to list the element items from our 'List of Menu Items' folder within 'Page One' of the site. However, we want to list the same menu of items from the 'List of menu items' folder from within the sub pages under 'Page One' - I'm just unsure of how to do this? 

    The current method we're using to call up the items within 'List of menu items' from 'Page One' is:

    @foreach(var type in Model.Content.Descendants("List of menu items"))

    This works fine, but of course if we house this same function within the children pages, it's looking for decendants of the children page. 

    If I use Model.Content.Ancestors - this also doesn't seem to work? 

    I appreciate your help.

    Kind Regards
    Marc

  • Alex Skrypnyk 6155 posts 24115 karma points MVP 8x admin c-trib
    Apr 10, 2015 @ 14:53
    Alex Skrypnyk
    0

    Hi Marc,

    Welcome to the best community. As I understand you want to create dynamic menu.

    @foreach(var type in Model.Content.Descendants("List of menu items"))

    This is hard coded menu, you have to the 'List of menu items' siblings via code.

    Try to use: Model.Content.AncestorsOrSelf(), and than Descendants.

    THis isn't perfect solution for performance.

    Thanks

  • Marc 2 posts 22 karma points
    Apr 10, 2015 @ 17:00
    Marc
    0

    Hi Alex,

    Thanks for your help with this - could you help me clarify one thing.

    My @foreach now looks like this: @foreach(var page in Model.Content.AncestorOrSelf("ProjectType").Children)
    This isn't throwing up any errors, however my next error set is the call within the @foreach function. 

    In my origional function: @foreach(var type in Model.Content.Descendants("ProjectType"))  I'm able to pick up a content type and it renders correctly:

    <[email protected](typeString == type.Id.ToString() ? " class=\"active\"": "")><a href="[email protected]" data-filter-value=".t@(type.Id)">@type.Name</a></li>

    However, when I run the new @foreach function on my children pages, I'm getting an error:

     CS0103: The name 'type' does not exist in the current context

    Can I assume my new @foreach function on my children page is picking up the "ProjectType" folder now, is it? If so, and I'm not getting an error, why isn't it picking up my @type string?

    Regards 

  • Alex Skrypnyk 6155 posts 24115 karma points MVP 8x admin c-trib
    Apr 10, 2015 @ 19:04
    Alex Skrypnyk
    0

    Marc, are you using var type in the children view ? Can you show all your code ?

    Thanks

Please Sign in or register to post replies

Write your reply to:

Draft