Copied to clipboard

Flag this post as spam?

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


  • Poornima Nayar 106 posts 276 karma points MVP 5x c-trib
    Oct 18, 2017 @ 21:34
    Poornima Nayar
    0

    Nested Content With ModelsBuilder

    Hi,

    With Nested Content in core will I be able to query any of my nested content properties as strongly typed models?

    Poornima

  • Kevin Jump 2310 posts 14694 karma points MVP 7x c-trib
    Oct 19, 2017 @ 09:28
    Kevin Jump
    0

    Hi

    Short answer - no it hasn't changed - in 7.7.2 nested content items still return IEnumerable<IPublishedContent> so you can't query them in a linq way.

    As there are content types in the nested content - there will be a model for the class generated so you can construct that from the IPublishedContent item and use it like a model.

    e.g. this in the current starter-kit product.cshtml page

      @if (Model.Content.Features != null)
      {
         foreach (var feature in Model.Content.Features)
         {
            <div class="product-advantage">
                <h4>@feature.GetPropertyValue("featureName")</h4>
                <h5>@feature.GetPropertyValue("featureDetails")</h5>
            </div>
          }
      }
    

    can become

     @foreach (var feature in Model.Content.Features)
     {
        var featureModel = new ContentModels.Feature(feature);
        <div class="product-advantage">
           <h4>@featureModel.FeatureName</h4>
           <h5>@featureModel.FeatureDetails</h5>
        </div>
     }
    

    n.b the starter kit has

    @using ContentModels = Umbraco.Web.PublishedContentModels; 
    

    at the top of the view. so that the ContentModels.Feature(feature) line is really new Umbraco.Web.PublishedContentModels.Feature(feature)

Please Sign in or register to post replies

Write your reply to:

Draft