Copied to clipboard

Flag this post as spam?

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


  • strawberrylatte 34 posts 103 karma points
    Mar 29, 2021 @ 04:17
    strawberrylatte
    0

    How to use nested content

    I wanted a button like feature(the picture kind of acts like a button) to repeat as long as nested content info is available. My nested content, called Portals consist of Link, Title and Picture. I would like to use the data in my nested content for my page.

    <div class="gdlr-core-event-item-list gdlr-core-style-grid gdlr-core-item-pdlr gdlr-core-column-20 gdlr-core-column-first  clearfix" style="margin-bottom: 45px ;">
                                        <div class="gdlr-core-event-item-thumbnail">
                                            <div class="gdlr-core-event-item-thumbnail-image gdlr-core-media-image  gdlr-core-opacity-on-hover gdlr-core-zoom-on-hover">
                                                <a href="#"><img src='#' width="700" height="450" alt="" /></a>
                                            </div>
                                        </div>
                                        <div class="gdlr-core-event-item-content-wrap">
                                            <h3 class="gdlr-core-event-item-title"><a href="#"></a></h3>
    
                                        </div>
                                    </div>
    

    This is what I'm aiming for

    enter image description here

  • strawberrylatte 34 posts 103 karma points
    Mar 29, 2021 @ 06:06
    strawberrylatte
    0

    Anyone?

  • Marc Goodson 2155 posts 14406 karma points MVP 9x c-trib
    Mar 29, 2021 @ 06:12
    Marc Goodson
    0

    Hi strawberrylatte

    It depends a little on your approach to templating, whether you are using Modelsbuilder etc but I think this is the gist of what you are asking

    If the alias of your NestedContent item is called 'portals', then you can get a list of all the nested content items the editor has entered with something like the following:

    @{
    var portals = Model.Value<IEnumerable<IPublishedElement>>("portals");
    var hasPortals = portals!=null && portals.any();
    
    }
    
    // and then you can display your data with:
    @if (hasPortals){
    // show somethng that only shows if there are buttons...
    
    // loop through each portal nested content item
        foreach (var portal in portals){
          <h3 class="gdlr-core-event-item-title"><a href="#">@(portal.Value<string>("title"))</a></h3>
    
        }
    
    }
    

    if that helps? or have I misread...

    regards

    Marc

  • strawberrylatte 34 posts 103 karma points
    Mar 29, 2021 @ 06:41
    strawberrylatte
    0

    thank you Marc, it helps, but there are some parts that I'm stuck with, since I am very new with umbraco. I couldn't get the data from link and picture

      @{
                                                    var portals = Model.Value<IEnumerable<IPublishedElement>>("portals");
                                                    var hasPortals = portals != null;
    
                                                }
    
    
                                                @if (hasPortals)
                                                {
                                                    // show somethng that only shows if there are buttons...
    
                                                    // loop through each portal nested content item
                                                    foreach (var portal in portals)
                                                    {
                                                        <img [email protected]("picture")) width="700" height="450" alt="" />
                                                        <h3 class="gdlr-core-event-item-title"><a [email protected]("link"))>@(portal.Value<string>("title"))</a></h3>
    
                                                    }
    
                                                }
    
  • Nevin George 12 posts 82 karma points
    Apr 03, 2021 @ 07:26
    Nevin George
    0

    Hi strawberrylatte,

    You can take the link and picture value by doing the following

    @{

    @using umbraco.web.models; // to get the umbraco Link model

    }

                                            @if (hasPortals)
                                            {
                                                // show somethng that only shows if there are buttons...
    
                                                // loop through each portal nested content item
                                                foreach (var portal in portals)
                                                {
                                                    <img [email protected]<IpublishedContent>("picture").Url()) width="700" height="450" alt="" />
                                                    <h3 class="gdlr-core-event-item-title"><a [email protected]<Link>("link").Url)>@(portal.Value<string>("title"))</a></h3>
    
                                                }
    
                                            }
    
Please Sign in or register to post replies

Write your reply to:

Draft