Copied to clipboard

Flag this post as spam?

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


  • Floffy 26 posts 33 karma points
    Mar 28, 2015 @ 19:06
    Floffy
    0

    iterate prevalues and list page with value

    Using umbraco 7.2.1 on windows 7, .net 4.0

    I got a custom datatype (dropdown) "category".

    In a Partiel View Macro, plaved  on a page with subpages that has the category set, i want to iterate the possible category values and under a heading list all pages that have the value in the categoy.

    I can iterate, but the selection returns 0 node for all the values that are listet.

    What an I doing wrong? 

    @{
    var iterator = umbraco.library.GetPreValues(1142);
    iterator.MoveNext();
    var preValues = iterator.Current.SelectChildren("preValue", "");
    while (preValues.MoveNext())
    {
    var type = preValues.Current.Value;
    <h2>@type</h2>
    var selection = CurrentPage.Children.Where("category == " + type).OrderBy("Name");
    @selection.Count()
    }
    }

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Mar 28, 2015 @ 22:45
    Jeavon Leopold
    0

    Hi there, if I've understood you correctly, give this a try:

    @{
        var preValues = ApplicationContext.Services.DataTypeService.GetPreValuesByDataTypeId(1442);
    
        foreach (var preValue in preValues)
        {
            var childrenNodes = CurrentPage.Children.Where("category.ToLower() == @0", preValue.ToLower());
            if (childrenNodes.Any())
            {
                <p>Nodes with @preValue selected:</p>
                <ul>
                    @foreach (var page in childrenNodes)
                    {
                        <li><a href="@page.Url"> @page.Name</a></li>
                    }
                </ul>
            }
        }
    }
    

    Jeavon

  • Floffy 26 posts 33 karma points
    Mar 28, 2015 @ 23:13
    Floffy
    0

    Perfect :)

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Mar 29, 2015 @ 00:05
    Jeavon Leopold
    0

    Great!

Please Sign in or register to post replies

Write your reply to:

Draft