Copied to clipboard

Flag this post as spam?

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


  • blackhawk 313 posts 1368 karma points
    Jul 01, 2017 @ 04:27
    blackhawk
    0

    How to get length of models if they exist with Archetype

    I'm on Umbraco 7.6.3 and using Archetype 1.14.1. I feel im making good strides with getting this package to work. I would like to take things further with my partial views, and get the total number of models that exist and display them. This is what I'm currently using on my partial view template....

    @inherits UmbracoViewPage<List<umb02.Models.Featureditem>>
    @using umb02.Models;
    
    <div class="container custom-grid">
        <div class="row">
            <div class="col-md-6">
                @RenderFeaturedItem(Model[0], null)
            </div>
            <div class="col-md-6">
                @RenderFeaturedItem(Model[1], null)
            </div>
    
        </div>
    </div>
    
    @helper RenderFeaturedItem(Featureditem item, string extraClass) { 
    
        <div class="featured-grid @extraClass">
            <div class="desc">
                <h3>@item.Name</h3>
                <span>@item.Category</span>
                <span><img src="@item.ImageUrl" alt=""></span>
                <span><a href="@item.LinkUrl">@item.LinkUrl</a></span>
            </div>
        </div>
        }
    

    How can I get all @RenderFeaturedItem(Model[x], null) items that exist and populate them onto page, rather than hard-coding each one onto page?

    Thanks

  • Kevin Jump 2311 posts 14696 karma points MVP 7x c-trib
    Jul 01, 2017 @ 09:42
    Kevin Jump
    100

    Hi,

    As your template is getting a list of items, You should be able to use a for-each to loop through all the items.

    <div class="row">    
        @foreach(var item in Model) 
        {
           <div class="col-md-6">
              @RenderFeaturedItem(item, null)
           </div>
        }
    </div>
    
Please Sign in or register to post replies

Write your reply to:

Draft