Copied to clipboard

Flag this post as spam?

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


  • bh 444 posts 1544 karma points
    Jul 24, 2017 @ 19:19
    bh
    0

    How to render Nested Content widget on Page

    I've got a Nested Content widget that has a DocType and a Template. How do I add the template for my widget to the template for my page?

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Jul 24, 2017 @ 19:33
    Alex Skrypnyk
    0

    Hi Bh

    You can use just all fields, if you have only one item as nested content:

    var item = Model.GetPropertyValue<IPublishedContent>("nestedContentPropertyAlias");
    
    @item.GetPropertyValue("header")
    

    If you have multiple items:

    var items = Model.GetPropertyValue<IEnumerable<IPublishedContent>>("nestedContentPropertyAlias");
    
    foreach (var item in items)
    {
        @item.GetPropertyValue("header")
    }
    
  • bh 444 posts 1544 karma points
    Jul 24, 2017 @ 19:36
    bh
    0

    I appologize if this is a stupid question. But, isn't that what I would use on the template for my widget to render the widget properties on my widget's template? What would I use on the template for my page to render the entire widget on my page?

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Jul 24, 2017 @ 21:40
    Alex Skrypnyk
    0

    You will use it on the page where the widget will be.

  • bh 444 posts 1544 karma points
    Jul 25, 2017 @ 12:17
    bh
    0

    Thanks for your response @AlexSkrypnyk How do I add the template for my widget to the template for my page? I'm sorry if I'm not using the correct terminology here. I'll provide the code I'm using now and maybe that'll clarify the trouble i'm having...

    The DocType for my widget is called "wLefty", the DocType for my page is called "Demo".

    The template for my Nested Content widget is called wLefty and here is that code...

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage<ContentModels.WLefty>
    @using ContentModels = Umbraco.Web.PublishedContentModels;
    @{
        Layout = null;
        var item = Model.GetPropertyValue<IPublishedContent>("wLefty")
    }
    
    <div class="clearfix"></div>  
    <div class="row-fluid clearfix noPadding rowMargin">
        <div class="col-xs-12 col-sm-10 col-sm-offset-1 col-lg-8 col-lg-offset-2 nopadding lefty-container">
            <div class="col-xs-12 col-sm-10 col-sm-offset-2 nopadding lefty-background">
                <img src="@Umbraco.Field(item, "wLeftyImage")" class="xs-img-responsive" />
            </div>
           <div class="col-xs-10 col-xs-offset-1 col-sm-5 col-sm-offset-0 col-lg-4 lefty-page">
                @if (string.IsNullOrWhiteSpace(@Umbraco.Field(item, "wLeftyCursive")) == false){
                    <h3 class="handwritten">@Umbraco.Field(item, "wLeftyCursive")</h3>
                }
                <h2>@Umbraco.Field("wLeftyTitle")</h2>
                <div class="BGhr-container"><div class="BGhr">&nbsp;</div></div>
                @Umbraco.Field(item, "wLeftyCopy")
                @if (string.IsNullOrWhiteSpace(@Umbraco.Field(item, "wLeftyButtonLink")) == false){
                    <div class="abtnContainer center-block"><a href="@Umbraco.Field(item, "wLeftyButtonLink")" class="aBtn allcaps">Button<i class="fa fa-chevron-right" aria-hidden="true"></i></a></div>
                }
            </div>
        </div>
    </div>
    

    The template for my page is called Demo (this is where I'm unclear how to add the widget to my page template)...

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @{
        Layout = "Page.cshtml";
    }
    
    @* the fun starts here *@
    <h1>LEFTY</h1>
    @* How do I add my wLefty widget here? *@
    
  • Greg 12 posts 102 karma points
    Aug 06, 2019 @ 13:43
    Greg
    0

    Did you ever figure this out?

  • bh 444 posts 1544 karma points
    Aug 06, 2019 @ 15:00
    bh
    0

    @Greg yes sir I did get it figured out with a boat load of help from @AlexSkrypnyk.

    @if(Model.Content.GetPropertyValue<IEnumerable<IPublishedContent>>("theAttributeNameOnMyPageDocType") != null){
                    <span class="small">@Html.Partial("wLefty",Model.Content.GetPropertyValue<IEnumerable<IPublishedContent>>("theAttributeNameOnMyPageDocType"))</span>
                }
    
Please Sign in or register to post replies

Write your reply to:

Draft