Copied to clipboard

Flag this post as spam?

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


  • Gert 81 posts 288 karma points
    May 12, 2014 @ 13:19
    Gert
    0

    Siblings doesn't return any elements

    Hi, I'm trying to implement a language selector. In the content node I have two home pages (see screenshot), each assigend a different culture. In the code below, the call CurrentPage.AncestorOrSelf( 1 ).Siblings() doesn't return any elements, so the code inside the foreach loop is never called. Any idea what I am doeing wrong? Much Thanks!

    enter image description here

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    @using System.Linq;
    @{
        var homePages = CurrentPage.AncestorOrSelf( 1 ).Siblings();
            <div class="lang">
                <ul>
                    @foreach ( var page in homePages )
                    {
                        <li><a href="@page.Url">@Umbraco.Field( "LanguageTekst", recursive: true )</a></li>
                    }
                </ul>
            </div>
    
  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    May 12, 2014 @ 13:26
    Dennis Aaen
    0

    Hi Gert,

    How about this: If you see the cheat sheet for Razor MVC, I know it´s for version 6, but if you look at it the Sibling() and it taks an int.

    http://our.umbraco.org/projects/developer-tools/umbraco-v6-mvc-razor-cheatsheets

    @inheritsUmbraco.Web.Macros.PartialViewMacroPage
    @usingSystem.Linq;
    @{
       
    var homePages = CurrentPage.AncestorOrSelf(1).Sibling();
           
    <div class="lang">
               
    <ul>
                   
    @foreach(var page in homePages )
                   
    {
                       
    <li><a href="@page.Url">@Umbraco.Field("LanguageTekst", recursive:true)a></li>
                   
    }
               
    </ul>
          </
    div>

    Hope this helps,

    /Dennis

  • Gert 81 posts 288 karma points
    May 12, 2014 @ 14:06
    Gert
    0

    Hi Dennis,

    Thank you for your reply! On Umbraco TV this was done with the Siblings() call (see screenshot), that's why I tried this. Perhaps this worked in a previous version and doensn't work anymore in version 7?

    enter image description here

    What is the meaning exactly of the integer parameter? Is it the next x-siblings? Whatever value I pass into the Sibling() method call, it allways retuns null?

    var homePages = CurrentPage.AncestorOrSelf( 1 ).Sibling(1); // returns null
    var homePages = CurrentPage.AncestorOrSelf( 1 ).Sibling(2); // returns null
    

    Any idea what I'm doing wrong?

    Much thanks!

    Gert.

  • Gert 81 posts 288 karma points
    May 12, 2014 @ 18:14
    Gert
    100

    I resolved the problem by looking for the different home pages based on the document type like this.

    var homePages = Umbraco.TypedContentAtRoot().Where( p => p.DocumentTypeAlias == "Home" );
    

    Gert.

  • SlawekN 4 posts 24 karma points
    May 07, 2015 @ 13:31
    SlawekN
    0

    This worked for me for Umbraco 7.2.0:

    foreach (var homePageNode in CurrentPage.AncestorOrSelf(2).ContentSet)
    {
        <li class=""><a href="@homePageNode.Url">@homePageNode.Name</a></li>
    }

    And this also:

    foreach (var langHomePageNode in Model.Content.Siblings())
    {
        bool isActive = CurrentPage.Id == langHomePageNode.Id;
        string activeClass = isActive ? "active" : "";
        <li class="@activeClass"><a href="@langHomePageNode.Url">@langHomePageNode.Name</a></li>
    }
  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies