I have however decided that it will be better if the editor does not have to maintain the multi-node list because it's really just a list of the top level pages.
I would like to dynamically create the node ID list and then pass it to the RenderTemplate macro.
I have this Razor script which will generate the node ID list:
@inherits umbraco.MacroEngines.DynamicNodeContext @{ string ids = ""; var parent = @Model.AncestorOrSelf(2); if (parent != null) { foreach (var page in parent.MainPage.Where("Visible")) { ids = @Library.Join(",", ids, page.Id);
} } }
but is there someway to then use it in the RenderTemplate macro or is the only way to create a wrapper macro?
I'd go with the solution in the blog post... a wrapper macro - seems like the path of least resistance!
I take it that you are using uComponents' RenderTemplate control? If so, you could probably just call that directly, no need for the extra macro container.
I can provide a code snippet later if you want? (haven't got time at this moment) :-)
The approach I was thinking would create the control in code...
<%@ Import Namespace="uComponents.Core" %>
<%@ Import Namespace="uComponents.Core.uQueryExtensions" %>
<script runat="server">
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
var level2Nodes = uQuery.GetNodesByXPath("//*[@isDoc and @level = 2]");
if (level2Nodes != null)
{
var nodeIds = string.Join(",", level2Nodes.Select(n => n.Id));
var renderTemplate = new uComponents.Core.Controls.RenderTemplate() { NodeIds = nodeIds };
this.Controls.Add(renderTemplate); // change this to add the control to something better, like a PlaceHolder.
}
}
</script>
Since you are already using uComponents, you can take advantage of the uQuery helper methods to get the nodes that you want.
As with most things in Umbraco, there are many ways to tackle these problems... all good fun! :-)
Dynamic macro parameter - passing the results of one macro to another?
I'm using a macro that takes a list of node IDs as a parameter:
<umbraco:Macro Alias="RenderTemplate" NodeIds="1201,1202,1203" runat="server"></umbraco:Macro>
I was using a multi-node picker and passing in the values like so:
<umbraco:Macro Alias="RenderTemplate" NodeIds="[$MainPages]" runat="server"></umbraco:Macro>
I have however decided that it will be better if the editor does not have to maintain the multi-node list because it's really just a list of the top level pages.
I would like to dynamically create the node ID list and then pass it to the RenderTemplate macro.
I have this Razor script which will generate the node ID list:
@inherits umbraco.MacroEngines.DynamicNodeContext
@{
string ids = "";
var parent = @Model.AncestorOrSelf(2);
if (parent != null)
{
foreach (var page in parent.MainPage.Where("Visible"))
{
ids = @Library.Join(",", ids, page.Id);
}
}
}
but is there someway to then use it in the RenderTemplate macro or is the only way to create a wrapper macro?
Regards,
Matt
Hi Matt,
I'd go with the solution in the blog post... a wrapper macro - seems like the path of least resistance!
I take it that you are using uComponents' RenderTemplate control? If so, you could probably just call that directly, no need for the extra macro container.
I can provide a code snippet later if you want? (haven't got time at this moment) :-)
Cheers, Lee.
Hi Lee,
Yes I'm using the uComponents RenderTemplate control.
I have successfully implemented the solution in the blog post and it's working well.
Always interested in seeing your method if you get the time.
Regards,
Matt
I suspect you mean I could place the following in my control
and then set the node ids in my code behind logic
I think that's better.
:)
Hi Matt,
Cool, I think that works very well! :-D
The approach I was thinking would create the control in code...
Since you are already using uComponents, you can take advantage of the uQuery helper methods to get the nodes that you want.
As with most things in Umbraco, there are many ways to tackle these problems... all good fun! :-)
Cheers, Lee.
Thanks Lee,
I certainly am using uQuery too! :)
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.