Copied to clipboard

Flag this post as spam?

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


  • riski 11 posts 101 karma points
    Feb 02, 2018 @ 03:23
    riski
    0

    How use CurrentPage.Children in Currentpage.getgridhtml

    I have question how to insert CurrentPage.Children in Currentpage.getgridhtml. i see example about blog content and i get the template like this:

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @{
        Layout = "Master.cshtml";
    }
    <div class="journey section">
            <div class="container">
    
                <div class="row">
                    @foreach(var post in CurrentPage.Children) 
                    {
                        <div class="col-sm-3">
                            <div class="content equal">
                                <a href="@post.Url">
                                    <div class="date">@post.CreateDate.ToLongDateString()</div>
                                    <h2>@post.Name</h2>     
                                    <p>@Umbraco.Truncate(post.Introduction, 240, true)</p>
                                </a>
                            </div>
                        </div>
                    }
                </div>
            </div>
    </div>
    
    </div>
    

    and i create custom template name is "category" just page content not like blog, like this :

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @{
        Layout = "Master.cshtml";
    }
    @CurrentPage.GetGridHtml("content", "category")
    

    my trouble is how to use :

    <div class="row">
                    @foreach(var post in CurrentPage.Children) 
                    {
                        <div class="col-sm-3">
                            <div class="content equal">
                                <a href="@post.Url">
                                    <div class="date">@post.CreateDate.ToLongDateString()</div>
                                    <h2>@post.Name</h2>     
                                    <p>@Umbraco.Truncate(post.Introduction, 240, true)</p>
                                </a>
                            </div>
                        </div>
                    }
                </div>
    

    from blog inside @CurrentPage.GetGridHtml("content", "category") file in => "partial views->grid->category"

    i try to add blog code for get child page introduction inside :

    @helper renderRow(dynamic row, bool singleColumn) 
    {
    ... // blog code for get the child
    }
    

    but i can't get the ouput.

  • Kevin Jump 2342 posts 14889 karma points MVP 8x c-trib
    Feb 02, 2018 @ 10:22
    Kevin Jump
    0

    Hi

    I am not sure you can do this directly in the grid* The model that is passed to a grid view is actual that of the grid markup (so the json for the grid not the content page).

    Also if you put the code in the grid then it will execute no matter what content someone puts in your grid, this may be what you want, but it would be better to have a separate partial to go get the child content, and render it out.

    I suspect what you want is closer to what is inside the current starter kit for umbraco where - the a list of blog pages is written out inside a grid block. this is achieved via a macro, that is then inserted (by the editor) inside the grid code.

    blog macro listing in the starter kit

    the actual code to display the children/blog is within the Macro code, and not the grid - when the grid template encounters the macro it calls that code, this allows it to be separate and not change the grid rendering.

    the best way to see this might be to quickly install a new version of umbraco and do a default install - you can then see this in the starter kit.

    but the source code is here : https://github.com/umbraco/The-Starter-Kit with the maco code being here: https://github.com/umbraco/The-Starter-Kit/blob/master/src/Umbraco.SampleSite.Website/Views/MacroPartials/LatestBlogposts.cshtml

    *You might be able to 'do' this within the grid using Umbraco.AssignedContentItem to get the current Content object for the page, but i don't thing that's right (and it may not actually be accurate)

Please Sign in or register to post replies

Write your reply to:

Draft