Copied to clipboard

Flag this post as spam?

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


  • manila 240 posts 542 karma points
    Jul 24, 2014 @ 12:21
    manila
    0

    check Archetype items' Count or Length

    How to check how many items is in testimonials Archetype value?

    I have

    var testimonials = settingsNode.GetPropertyValue<Archetype.Models.ArchetypeModel>("testimonialsWidget");
    

    then

    var counter = 1;
    foreach (var item in testimonials)   {
        //var last = counter == testimonials.Count ? " class=\"last\"" : "";
        <div class="item">
            <p>"@item.GetValue("text")"</p>
        </div>
        counter++;
    }
    

    'testimonials' have no Count or Length value.

    Thanks

  • Jeavon Leopold 3000 posts 13161 karma points MVP 6x admin c-trib
    Jul 30, 2014 @ 17:33
    Jeavon Leopold
    0

    Hi Eva,

    Something like this:

        var testimonials = Model.Content.GetPropertyValue<ArchetypeModel>("testimonialsWidget");
    
        <p>Number of items in testimonials: @testimonials.Count()</p>
    
        foreach (var item in testimonials)
        {
            var lastClass = item.Equals(testimonials.Last()) ? "last" : null;
    
            <div class="@lastClass">
                <p>@item.GetValue("text")</p>
            </div>
        }
    

    Jeavon

  • manila 240 posts 542 karma points
    Jul 30, 2014 @ 17:45
    manila
    0

    Thanks Jeavon. Your example works, my example does not work because it is on other than current node.

    See my comment here: http://our.umbraco.org/projects/backoffice-extensions/archetype/sound-off!/55062-check-Archetype-items-Count-or-Length

    I;m still looking for a solution.

  • Allan 38 posts 186 karma points
    Dec 12, 2018 @ 11:45
    Allan
    1

    Had the same sort of issue here. I needed to count the number of items in Archetype before I began looping/using them.

    I found this did not work -

    var thing = Model.Content.GetPropertyValue<ArchetypeModel>("things");
    @thing.count()
    

    But I did find that this worked...

    ArchetypeModel thing = Model.Content.GetPropertyValue<ArchetypeModel>("things");
    @thing.Count()
    
Please Sign in or register to post replies

Write your reply to:

Draft