Copied to clipboard

Flag this post as spam?

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


  • Jeppe Volander Rasmussen 16 posts 138 karma points
    Aug 07, 2018 @ 12:41
    Jeppe Volander Rasmussen
    0

    Models Builder (PureLive)

    Hey Guys,

    This may be a silly question, but I can't figure it out. How do i get all products and not the featured products? How should the foreach statement look like? While still using the models builder ofc.

    @inherits UmbracoTemplatePage<Products>
    @using ContentModels = Umbraco.Web.PublishedContentModels;
    @{
        Layout = "Master.cshtml";
    }
    
    
        <div class="product-grid">
            @if (Model.Content.FeaturedProducts != null)
            {
                foreach (Product product in Model.Content.FeaturedProducts)
                {
                    <a href="@product.Url" class="product-grid__item" style="background-image: url('@product.Photos.FirstOrDefault().Url')">
                        <div class="product-grid__item__overlay">
                            <div class="product-grid__item__name">@product.ProductName</div>
                            <div class="product-grid__item__price">@Model.Content.DefaultCurrency @product.Price.ToString("F")</div>
                        </div>
                    </a>
                }
            }
        </div>
    
  • Paul Tilsed 26 posts 179 karma points c-trib
    Aug 08, 2018 @ 14:38
    Paul Tilsed
    0

    Hi Jeppe,

    Assuming this is your products page and all your products sit below it as children with no other types of document you could use this:

    foreach(Product product in Model.Content.Children().Select(p => new Product (p)))
    {
        //Markup required
    }
    

    Models Builder only know's the properties that belong to that specific piece of content. You have to perform additional logic away from the Model or adjust the model to match your needs.

    Hope this helps,

    Paul

Please Sign in or register to post replies

Write your reply to:

Draft