Copied to clipboard

Flag this post as spam?

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


  • Lasya 38 posts 70 karma points
    Mar 20, 2014 @ 12:39
    Lasya
    0

    Siblings of a rootnode in the Content

    Hi

    I am working on a multilingual website and i need to extract Siblings of a root node with razor code  to match language name/rootnode name with browser language.

    Thanks,

    Lasya.

  • Lasya 38 posts 70 karma points
    Mar 20, 2014 @ 12:43
    Lasya
    0

    I have tried like this

    var sibs = Model.AncestorOrSelf().Descendants("umbHomePage").Items;

    <ul>
        @foreach (var itemNode in sibs)
        {

      <li><a href="@itemNode.Url">@itemNode.Name</a></li>
               
        }
    </ul>

    and

    var sibs = Model.AncestorOrSelf(1).Siblings("umbHomePage");

    <ul>
        @foreach (var itemNode in sibs)
        {

      <li><a href="@itemNode.Url">@itemNode.Name</a></li>
               
        }
    </ul>

     

    But no use.

    Thanks,

    Lasya

     

  • Fuji Kusaka 2203 posts 4220 karma points
    Mar 20, 2014 @ 12:47
    Fuji Kusaka
    0

    Try this

    @using umbraco.MacroEngines;
    @using umbraco.BusinessLogic
    @{
    
                List<DynamicNode> sibs = Model.AncestorOrSelf(2).Descendants("docType").Items;
    foreach(var itemNode in sibs){
    @itemNode.Name
    }
  • Lasya 38 posts 70 karma points
    Mar 20, 2014 @ 12:54
    Lasya
    0

    Hi Fuji

    It is throwing an error

    Error loading MacroEngine script(file: DetectLanguage.cshtml)

    thnks,

    Lakshmi.

  • Fuji Kusaka 2203 posts 4220 karma points
    Mar 20, 2014 @ 13:10
    Fuji Kusaka
    0

    Hi Laskmi,

    Can you please post your full code ?

  • Lasya 38 posts 70 karma points
    Mar 20, 2014 @ 13:18
    Lasya
    0

    @inherits umbraco.MacroEngines.DynamicNodeContext

    @{
      @*
    Get value of UserLanguages from HttpContext Object
    This is Browser Language Setting
    This is returned as an array, as it can have more than one language
    The first value in the arrary is the default or preferred language
    Value is returned as language-culture (eg en-gb), so we might need to trim to just get language code
    *@
        var contentRoot = Model.AncestorOrSelf(1);
       
        var lang = System.Web.HttpContext.Current.Request.UserLanguages[0];
        <div>@lang</div>
        var langName = lang.ToString().Substring(0, 2);
        var nodeName = Model.Name;
        var sibs = Model.AncestorOrSelf().Descendants("umbHomePage").Items;
          
           
    }

    <ul>
        @foreach (var itemNode in sibs)
        {
           
            <li><a href="@itemNode.Url">@itemNode.Name</a></li>
               
        }
    </ul>
           

    this is my code

    once i get all the sibling node names(my node names are like en, her, fr, da etc.,) then i will write a condition if var itemNode.Name equals to langName then redirect to that language home page.

    Thanks

  • Lasya 38 posts 70 karma points
    Mar 20, 2014 @ 16:13
    Lasya
    0

    Hello

    Any help to get Root node siblings with razor script Please.

    Thanks

  • Fuji Kusaka 2203 posts 4220 karma points
    Mar 20, 2014 @ 18:57
    Fuji Kusaka
    0

    Hi Lasya,

    Let me get this right, you are working with a multilingual website right ? 

    If you have this following structure under the Content section 

    Content

    - En
    -- Item 1
    -- Item 2
    - Fr
    -- Item 1
    -- item 2
    - Da
    -- Item 1
    -- Item 2

    your script will automatically pick the content and display the Urls and Name of the content depending on the language you are.

     What do you get if you do something like thise 

    @using umbraco.MacroEngines;
    @using umbraco.BusinessLogic
    @{

               
    List<DynamicNode> sibs =Model.AncestorOrSelf(1).Descendants("docType").Items;
    foreach(var itemNode in sibs){
    @itemNode.Name
    }
    }

    /Fuji 

  • Fuji Kusaka 2203 posts 4220 karma points
    Mar 20, 2014 @ 20:32
    Fuji Kusaka
    0

    Replace the docType with the documentType name of the nodes you want to display

  • Lasya 38 posts 70 karma points
    Mar 24, 2014 @ 11:10
    Lasya
    0

    Hi Fuji

    I have tried your code and not displaying anything.

    I want to get my language nodes/homepages which are at level 1. en, fr, da, hr etc.,

    and i have dropped my razor macro in my home page template(i.e en node template).

     

    Thanks

  • Gert 81 posts 288 karma points
    May 12, 2014 @ 18:11
    Gert
    0

    Hi Laysa,

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

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

    I hope this helps!

    Kind Regards, Gert.

Please Sign in or register to post replies

Write your reply to:

Draft