Copied to clipboard

Flag this post as spam?

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


  • rehamhabbas 14 posts 103 karma points
    Jan 16, 2018 @ 13:09
    rehamhabbas
    0

    output tabs alias nested Content

    Hello I'm new to Umbraco

    I have a home page with 2 tabs one of the tabs is Facts-And-Figures-Content tab that has an Elias Facts-Figures-Items-Nested which is a nested Content from a Document Type without Template I need to ask now how can I output these items on home page template enter image description here

    much Thanks !

  • Nik 1612 posts 7258 karma points MVP 7x c-trib
    Jan 16, 2018 @ 14:10
    Nik
    1

    Hi Rehamhabbas,

    Accessing the nested content is a bit like accessing a normal property combined with access children of a node.

    Assuming the following:

    1) Your home node is of a document type called Home 2) Your nested content document types are called "FactsAndFigures" 3) The Facts-Figures-Items-Nested property has an alias of factsFiguresItemsNested 4) You are using Models Builder (which is normally on by default in the later versions of Umbraco)

    There are two ways to go about this:

    1)

    @{
        //This will give you an IEnumberable<IPublishedContent>
        var factsAndFigures = Model.Content.FactsFiguresItemsNested;
    
        foreach(var entry in factsAndFigures)
        {
             //You can access properties like any other IPublishedContent
             <div>@entry.Name</div>
        }
    }
    

    2) You can add a step of type-safe access by doing the following extra step:

    @{
        //This will give you an IEnumberable<IPublishedContent>
        var factsAndFigures = Model.Content.FactsFiguresItemsNested;
    
        foreach(var entry in factsAndFigures)
        {
              var typeSafeEntry = new FactsAndFigures(entry);             
             <div>@typeSafeEntry.Name</div>
        }
    }
    

    Hope that helps :-)

  • rehamhabbas 14 posts 103 karma points
    Jan 17, 2018 @ 08:28
    rehamhabbas
    0

    @nik enter image description here

    now how can I access the nested items inside

    Thanks

  • Nik 1612 posts 7258 karma points MVP 7x c-trib
    Jan 17, 2018 @ 08:52
    Nik
    1

    Hi Rehamhabbas,

    Accessing the internal properties is exactly the same as accessing them as if they were on a normal IPublishedContent.

    You can use GetPropertValue(), or if you go down the Models builder, type safe approach, they are just properties on the objects.

    So for example:

    @{
        //This will give you an IEnumberable<IPublishedContent>
        var factsAndFigures = Model.Content.FactsFiguresItemsNested;
    
        foreach(var entry in factsAndFigures)
        {
             //You can access properties like any other IPublishedContent
             <div>@entry.Name</div>
             <div>@entry.GetPropertyValue("svgFactsIcon")</div>
        }
    }
    
  • rehamhabbas 14 posts 103 karma points
    Jan 17, 2018 @ 08:57
    rehamhabbas
    0

    much appreciated your time and respond quickly I think I should go deeply with documentation and developers tutorial before starting my first project

    Thanks a lot

  • Nik 1612 posts 7258 karma points MVP 7x c-trib
    Jan 17, 2018 @ 08:59
    Nik
    1

    I highly recommend Umbraco TV as an introduction to using Umbraco. It's got decent tutorials that you can follow along with. :-)

Please Sign in or register to post replies

Write your reply to:

Draft