Copied to clipboard

Flag this post as spam?

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


  • Phillip Turner 98 posts 412 karma points
    Apr 06, 2016 @ 20:46
    Phillip Turner
    0

    Can I render GetGridHtml in a partial

    I would like to be able to render a GetGridHtml in a partial. IS there a way to achieve this?

    This is my current partial:

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @{
    var sections = CurrentPage.pageSections;
    int i = 0;
    string bookmarkID;
    }
    @foreach (var sec in sections)
    {
    i++;
    bookmarkID = string.Format("section-bookmark-{0}", i.ToString());
    <a name="@bookmarkID"></a>  
    <div class="container-fluid no-side-padding">
        <img src="@Umbraco.Media(sec.fullBannerImage.ToString()).Url" class="img-responsive hidden-xs" style="width:100%;" />
        <img src="@Umbraco.Media(sec.smallBannerImage.ToString()).Url" class="img-responsive visible-xs" style="width:100%;" />
    </div>
    <div class="container-fluid" style="background-color:#@sec.titleBandColor.ToString()">
        <div class="row">
            <div class="container no-side-padding">
                <div class="col-xs-12 page-title">
                    @sec.mainPageTitle
                </div>
            </div>
        </div>
    </div>
    <div class="container-fluid no-side-padding" style="background-color:#e8e8e8; padding-top: 20px;">
        <div class="row">
            <!-- Does Not Work -->
            @Umbraco.GetGridHtml(sec.bodyContent)
            <!-- Does Not Work -->
            @CurrentPage.GetGridHtml(sec.bodyContent)
        </div>
    </div>
    }
    

    Tree Structure

    main-page
       |
       ----- > page-section 1
       |
       ----- > page-section 2
    
  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Apr 06, 2016 @ 21:17
    Dennis Aaen
    0

    Hi Phillip,

    Could you try this

    @sec.GetGridHtml("bodyContent")

    Hope this helps,

    /Dennis

  • Phillip Turner 98 posts 412 karma points
    Apr 06, 2016 @ 21:21
    Phillip Turner
    0

    I tried... it renders empty.

    If I omit the GetGridHtml method, then the correct JSON is returned, but applying the method fails. Note that is does not give a runtime error.

  • Steve Morgan 1349 posts 4458 karma points c-trib
    Apr 07, 2016 @ 07:36
    Steve Morgan
    0

    Hi,
    try

    @(sec.GetGridHtml("bodyContent"))
    

    Sometimes the razor "renderer" need a bit of a hint where the tag ends.

  • Phillip Turner 98 posts 412 karma points
    Apr 07, 2016 @ 13:16
    Phillip Turner
    0

    Unfortunately that didn't work either. The output is blank. So the JSON is going somewhere and no runtime error is occurring.

  • Steve Morgan 1349 posts 4458 karma points c-trib
    Apr 07, 2016 @ 13:20
    Steve Morgan
    0

    Re-reading your code - what is making up these sections? Are you using LeBlender or something similar to create reoccuring sections?

    Steve

  • Phillip Turner 98 posts 412 karma points
    Apr 07, 2016 @ 13:29
    Phillip Turner
    0

    No.

    Each section is a document type called "page-section" and has no template.

    When the parent template is called, I call @Html.Partial("page-section"), which is the code I posted.

    Here is the code to the template:

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @{
    Layout = "ewMaster.cshtml";
    }
    <div class="container-fluid no-side-padding">
    <img src="@Umbraco.Media(Umbraco.Field("fullBannerImage").ToString()).Url" class="img-responsive hidden-xs" style="width:100%;" />
    <img src="@Umbraco.Media(Umbraco.Field("smallBannerImage").ToString()).Url" class="img-responsive visible-xs" style="width:100%;" />
    </div>
    @Html.Partial("ew-navigation")
    <div class="container-fluid" style="background-color:#@Umbraco.Field("titleBandColor").ToString()">
    <div class="row">
        <div class="container no-side-padding">
            <div class="col-xs-12 page-title">
                @Umbraco.Field("mainPageTitle")
            </div>
        </div>
    </div>
    </div>
    <div class="container-fluid no-side-padding" style="background-color:#e8e8e8; padding-top: 20px;">
    <div class="row">
        @CurrentPage.GetGridHtml("bodyContent")
    </div>
    </div>
    @Html.Partial("page-section")
    

    I am wondering if the GetGridHtml() is a help method for only templates and not partials and if I am missing a reference.

  • Steve Morgan 1349 posts 4458 karma points c-trib
    Apr 07, 2016 @ 13:29
    Steve Morgan
    0

    Sorry - re-reading again - your "sections" are actually child nodes, right? If so try:

    var sections = Model.Content.Children();
    

    ...

    @foreach  ( var sec in section ) {
     ...
    @(sec.GetGridHtml("bodyContent"))
    ..
    }
    
  • Phillip Turner 98 posts 412 karma points
    Apr 07, 2016 @ 13:31
    Phillip Turner
    0

    yes, they are children!

  • Phillip Turner 98 posts 412 karma points
    Apr 07, 2016 @ 13:40
    Phillip Turner
    0

    sec.GetGridHtml() throws a runtime error... Does not exist. I tried CurrentPage.GetGridHtml() and same results are my previous attempts... no errors, but no output at all.

    Umbraco.Core.Models.IPublishedContent' does not contain a definition for 'GetGridHtml'
    
  • Steve Morgan 1349 posts 4458 karma points c-trib
    Apr 07, 2016 @ 14:24
    Steve Morgan
    100

    Hi,

    CurrentPage is dynamic and I think causing you your issues.

    Try a cut back version of your partial page-sections - NOTE how I'm using the strongly typed Model.Content.Children():

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @{
        var sections = Model.Content.Children();
    
        foreach (var sec in sections)
        {
            <div>
                @sec.GetGridHtml("bodyContent");
            </div>
    
        }
    }
    

    I've just tested this locally and it works as expected.

  • Phillip Turner 98 posts 412 karma points
    Apr 07, 2016 @ 14:33
    Phillip Turner
    0

    ok, that worked. This is what I was doing wrong:

    @sec.GetGridHtml(sec["bodyContent"])
    

    and not

    @sec.GetGridHtml("bodyContent")
    

    Thanks for the replies

    • Phillip
  • Steve Morgan 1349 posts 4458 karma points c-trib
    Apr 07, 2016 @ 14:53
    Steve Morgan
    1

    Glad you're sorted!

Please Sign in or register to post replies

Write your reply to:

Draft