Update from 4.7.1 to 4.7.2, macro parameters stopped working
Hello,
I updated my site from 4.7.1 to 4.7.2, and the macro attributes / parameters stopped working with my razor macros. I have this template that calls then from code, passing parameters, but on the receiving macro, not parameter is found. Here is code I use:
var macros = new List<Macro>();
foreach (var section in CurrentModel.GetChildrenAsList.Items)
{
if (section.NodeTypeAlias == "ListOfLinks")
{
var macro = new Macro() { Alias = "ListOfLinks" };
macro.MacroAttributes.Add("NodeId", Convert.ToInt32(section.Id));
macros.Add(macro);
}
else if (section.NodeTypeAlias == "ListOfTitleTextImage")
{
var macro = new Macro() { Alias = "ListOfTitleTextImage" };
macro.MacroAttributes.Add("NodeId", Convert.ToInt32(section.Id));
macros.Add(macro);
}
}
var writer = new HtmlTextWriter(this.Output);
foreach (var macro in macros)
{
macro.RenderControl(writer);
}
And then in those macros:
@{
if (!string.IsNullOrEmpty(GetParameter("NodeId")))
{
var nodeId = Convert.ToInt32(GetParameter("NodeId"));
dynamic sectionNode = new DynamicNode(nodeId);
if(!string.IsNullOrEmpty(sectionNode.titre)) { <h3>@sectionNode.titre</h3> }
foreach (dynamic link in sectionNode.listeDeLiens)
{
var target = "";
if (link.newwindow == "True")
{
target = " target=\"_blank\"";
}
<a href="@link.url"@Html.Raw(target)>@link.linktitle</a><br />
}
}
}
In this code, the parameter NodeId is always "". This was working correctly before the site update.
Has anyone encountered a similar issue? Any ideas?
Make sure that you have specified your parameters for the macro in the Umbraco back office. I believe 4.7.1 allowed you to pass parameters without specifying them which was a bug.
Yes I had that behavior in 4.7.1, those parameters were not required to exist in the back office. I had them anyways. On 4.7.2, I tried with the parameters speficied in the backoffice and without. But same behavior in both. I'm looking at the implementation in that Razor Components package to see if I can get a better way to go about this.
Update from 4.7.1 to 4.7.2, macro parameters stopped working
Hello,
I updated my site from 4.7.1 to 4.7.2, and the macro attributes / parameters stopped working with my razor macros. I have this template that calls then from code, passing parameters, but on the receiving macro, not parameter is found. Here is code I use:
And then in those macros:
In this code, the parameter NodeId is always "". This was working correctly before the site update.
Has anyone encountered a similar issue? Any ideas?
Thanks for the help!
Apparently, wiring my parameter a different way works. But something in the update changed this. I wonder what it is.
Have you looked at the Razor Components package? It should make working with dynamic macros a lot simpler.
Make sure that you have specified your parameters for the macro in the Umbraco back office. I believe 4.7.1 allowed you to pass parameters without specifying them which was a bug.
John
Hi John,
Yes I had that behavior in 4.7.1, those parameters were not required to exist in the back office. I had them anyways. On 4.7.2, I tried with the parameters speficied in the backoffice and without. But same behavior in both. I'm looking at the implementation in that Razor Components package to see if I can get a better way to go about this.
Thanks
is working on a reply...