Copied to clipboard

Flag this post as spam?

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


  • nickornotto 403 posts 907 karma points
    Jul 24, 2014 @ 12:21
    nickornotto
    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 3074 posts 13632 karma points MVP 11x 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

  • nickornotto 403 posts 907 karma points
    Jul 30, 2014 @ 17:45
    nickornotto
    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 42 posts 192 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()
    
  • 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