Copied to clipboard

Flag this post as spam?

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


  • Andrew Bright 84 posts 244 karma points
    Jan 29, 2019 @ 12:59
    Andrew Bright
    0

    Featured products macro partial

    I have recently installed the template and just making tweaks, the products node which is created as part of the starter kit installation, I am looking to display these on the Homepage content section but can not get this to work.

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    
    This snippet lists the items from a Multinode tree picker, using the pickers default settings.
    Content Values stored as xml.
    
    To get it working with any site's data structure, set the selection equal to the property which has the
    multinode treepicker (so: replace "PropertyWithPicker" with the alias of your property).
    
    @{ var selection = CurrentPage.Content.Split(','); }
    
    <ul>
        @foreach (var id in selection)
        {
            var item = Umbraco.Content(id);
            <li>
                <a href="@item.Url">@item.Name</a>
            </li>
        }
    </ul>
    

    Not sure what the alias needs to be surely Products?

  • Andrew Bright 84 posts 244 karma points
    Jan 29, 2019 @ 13:58
    Andrew Bright
    0

    Managed to find a workaround by changing the selection variable:

    var selection = Model.Content.Site().FirstChild("products").Children("product")
                            .Where(x => x.IsVisible());
    

    I then updated the foreach loop to utilise this:

    <div class="product-grid">
            @foreach(var item in selection){
                // Product Images
                var photos = item.GetPropertyValue<IEnumerable<IPublishedContent>>("Photos");
                    <a href="@item.Url" class="product-grid__item" style="background-image: url('@photos.FirstOrDefault().Url')">
                        <div class="product-grid__item__overlay">
                            <div class="product-grid__item__name">@item.Name</div>
                        </div>
                    </a>
            }
    </div> 
    

    Just need to tweak to ensure it all takes featured products and 9 maximum which could perhaps be a macro parameter.

Please Sign in or register to post replies

Write your reply to:

Draft