Copied to clipboard

Flag this post as spam?

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


  • Anders Brohus 194 posts 475 karma points
    Jul 15, 2015 @ 12:24
    Anders Brohus
    0

    Can you render a macro inside the grid if current document type is "NewsPost"?

    Hi! :)

    Is it possible to render a macro inside the grid if the current document type is "NewsPost"?

    Because on a News Post, i got to render the title and date created and category ("Parents name"), but i can't find any thing about the current page when i debug the grid?

    The Grid layout is a two columns layout with the first column is 8 and second is 4, and i need the macro inside the top of the first :)

  • John Churchley 272 posts 1258 karma points c-trib
    Jul 15, 2015 @ 13:15
    John Churchley
    0

    Hi Anders,

    Are you using a package?

    There is no reason for this not to work. Is the problem the backend or front end? On the grid data type make sure you have allowed for marco editors.

  • Anders Brohus 194 posts 475 karma points
    Jul 15, 2015 @ 13:18
    Anders Brohus
    0

    I do use some packages :)

    LeBlender and AngularGoogleMaps, but nothing else :)

    I use the a custom grid render but it's based on the original Bootstrap 3 :)

  • John Churchley 272 posts 1258 karma points c-trib
    Jul 15, 2015 @ 13:22
    John Churchley
    0

    Have you tried..

    @Model.Content.GetGridHtml("gridpropertyalias","gridrendertemplate")

    Could you elaborate on the issue more it's not very clear what you mean.

  • Anders Brohus 194 posts 475 karma points
    Jul 15, 2015 @ 13:24
    Anders Brohus
    0

    Oh i got the grid to render no problems at all :)

    The problem is that while i call the

     @CurrentPage.GetGridHtml("textGrid", "OverAllGrid")
    

    I would like it to render a macro inside the grid if the document type is NewsPost :)

  • John Churchley 272 posts 1258 karma points c-trib
    Jul 15, 2015 @ 14:40
    John Churchley
    0

    Not sure you can get the information to the grid render maybe you could do all the render the JSON object in the page template to maintain access to IPublishedContent.

    Page Template

    @using Newtonsoft.Json.Linq
    
    @{
    dynamic textGrid = Model.Content.GetPropertyValue<string>("textGrid");
    }
    
    @if (textGrid != null && textGrid.sections != null)
    {
        var oneColumn = ((System.Collections.ICollection)textGrid.sections).Count == 1;
    
        <div class="umb-grid">
            @if (oneColumn)
            {
                foreach (var section in textGrid.sections)
                {
                    <div class="grid-section">
                        @foreach (var row in section.rows)
                        {
                            @renderRow(row, true);
                        }
                    </div>
                }
            }
            else
            {
                <div class="container">
                    <div class="row clearfix">
                        @foreach (var s in textGrid.sections)
                        {
                            <div class="grid-section">
                                <div class="[email protected] column">
                                    @foreach (var row in s.rows)
                                    {
                                        @renderRow(row, false);
                                    }
                                </div>
                            </div>
                        }
                    </div>
                </div>
            }
        </div>
    }
    
    @helper renderRow(dynamic row, bool singleColumn)
    {
        <div @RenderElementAttributes(row)>
            @Umbraco.If(singleColumn, "<div class='container'>")
            <div class="row clearfix">
                @foreach (var area in row.areas)
                {
                    <div class="[email protected] column">
                        <div @RenderElementAttributes(area)>
                            @foreach (var control in area.controls)
                            {
                                if (control != null && control.editor != null && control.editor.view != null)
                                {
                                    <text>@Html.Partial("grid/editors/base", (object)control)</text>
                                }
                            }
                        </div>
                    </div>}
            </div>
            @Umbraco.If(singleColumn, "</div>")
        </div>
    }
    
    @functions {
        public static MvcHtmlString RenderElementAttributes(dynamic contentItem)
        {
            var attrs = new List<string>();
            JObject cfg = contentItem.config;
    
            if (cfg != null)
                foreach (JProperty property in cfg.Properties())
                {
                    attrs.Add(property.Name + "=\"" + property.Value.ToString() + "\"");
                }
    
            JObject style = contentItem.styles;
    
            if (style != null)
            {
                var cssVals = new List<string>();
                foreach (JProperty property in style.Properties())
                    cssVals.Add(property.Name + ":" + property.Value.ToString() + ";");
    
                if (cssVals.Any())
                    attrs.Add("style=\"" + string.Join(" ", cssVals) + "\"");
            }
    
            return new MvcHtmlString(string.Join(" ", attrs));
        }
    }
    
  • Anders Brohus 194 posts 475 karma points
    Jul 16, 2015 @ 06:36
    Anders Brohus
    0

    Yeah i got the custom grid, as said i would like it while it gets rendered to see if it's a specific document type

Please Sign in or register to post replies

Write your reply to:

Draft