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 :)
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));
}
}
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 :)
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.
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 :)
Have you tried..
@Model.Content.GetGridHtml("gridpropertyalias","gridrendertemplate")
Could you elaborate on the issue more it's not very clear what you mean.
Oh i got the grid to render no problems at all :)
The problem is that while i call the
I would like it to render a macro inside the grid if the document type is NewsPost :)
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
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
is working on a reply...