Copied to clipboard

Flag this post as spam?

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


  • Emil Lindgren 28 posts 190 karma points
    Apr 08, 2020 @ 12:37
    Emil Lindgren
    0

    Cultured root node in controller

    Hello, i have a question about getting the cultured homenode in umbraco 8 in the controller.

    I have a homenode with different languages, example /it,/es, /sv. And i want to get the root node of these. and when im getting it with my code i only get the english version.

    anyone have any clue ? here is my code

     private List<IPublishedContent> GetProductsToFilter()
        {
    
            var home = Umbraco.ContentAtRoot().First();
            if (home == null)
                return null;
    
            var homeChildren = home.Children;
    
            var mainProductsPage = homeChildren?.Where(p => p.ContentType.Alias == "products").FirstOrDefault();
            if (mainProductsPage == null)
                return null;
    
            List<IPublishedContent> umbracoProducts = new List<IPublishedContent>();
            foreach (var products in mainProductsPage.Children)
            {
                // 1. We take 'products' with
                // 2. children of type 'filter'
                // 3. where is only one 'filter' child
                var productFilter = products.Children;
                if (productFilter == null)
                    continue;
    
                if (productFilter.Count() == 1 &&
                    productFilter.FirstOrDefault().ContentType.Alias.Equals("filterOption") &&
                    products.ContentType.Alias.Equals("products"))
                    umbracoProducts.Add(products);
            }
    
            return umbracoProducts;
        }
    

    Kind regards/ Emil

  • Yakov Lebski 591 posts 2346 karma points
    Apr 08, 2020 @ 14:26
    Yakov Lebski
    0

    I guess what you can change Thread culture?

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Apr 14, 2020 @ 20:41
    Alex Skrypnyk
    1

    Hi Emil

    Try this code for getting home node:

    var home = Umbraco.AssignedContentItem.AncestorOrSelf(1);
    

    How did you make a multicultural solution with Umbraco 8?

    Thanks, Alex

Please Sign in or register to post replies

Write your reply to:

Draft