Copied to clipboard

Flag this post as spam?

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


  • Nicky Christensen 76 posts 166 karma points
    Apr 09, 2013 @ 21:14
    Nicky Christensen
    0

    Only show boxes under current page

    Hey guys...

    Im having a bit of a problem with some boxes im trying to output...

    My sitetree looks like

    MainLink1
    MainLink2
    -  Box
    -  Subpage1
    - Box 
    -  Subpage2
    MainLink3

    Lets say im on the MainLink2 page, then I only want to display "Box" under that page, however, with my current script I also get the Box under Subpage 1, which I dont want... 
    If i were on the page Subpage1, then I would have the Box under Subpage1 displayed...

    Hope it makes sense :) 

    My script looks like:

    @inherits umbraco.MacroEngines.DynamicNodeContext

    @if (Model.Children.Where("Visible").Any())

    {           

            foreach (var childPage in Model.DescendantsOrSelf("SideBox").Where("Visible"))

            {

                var colorBox = @childPage.ColorLayout;

                

                if (colorBox == "red")

                {

                <div class="side-box red">

                    <div class="wrap-box">

                        @childPage.boxContent

                    </div>

                </div>

                }

                else if (colorBox == "grey")

                {

                <div class="side-box grey">

                    <div class="wrap-box">

                        @childPage.boxContent

                    </div>

                </div>

                }

                else

                {

                <div class="side-box">

                    <div class="wrap-box">

                        @childPage.boxContent

                    </div>

                </div>

                }


            }

    }

  • gary 385 posts 916 karma points
    Apr 09, 2013 @ 21:39
    gary
    101

    Hi Nicky

    The very simple way can be 

    foreach (var childPage in Model.DescendantsOrSelf("SideBox").Where("Visible").Take(1))

    This will only take one result, so will give you what you need.

    You could also try Model.Children("SideBox").Where("Visible") that should ignore the child of a child.

    However, as you are using a foreach loop I suspect that there could be more than one box you want to select under the node?

    If so then something like

    Model.DescendantsOrSelf(1).Where("NodeTypeAlias \"SideBox\"").Where("Visible")   should only go down one level. therefore only return the children of the current node. (Mode.Children("Sidebox) may achieve the same result)

    I take it you are using Webfroms razor? I use MVC razor so the calls may not be 100%, but I think you will see the method.

    Hope it helps

    Gary

     

     

     

  • Nicky Christensen 76 posts 166 karma points
    Apr 09, 2013 @ 21:48
    Nicky Christensen
    0

    Hey Gary...

    Thx alot, I'll give it a go :) 

Please Sign in or register to post replies

Write your reply to:

Draft