You could use this code below, with this you will get the child nodes from the current page, of a changeable source.
@inherits Umbraco.Web.Macros.PartialViewMacroPage
@*
Macro to list all child pages under a specific page in the content tree.
How it works:
- Confirm the startNodeId macro parameter has been passed in with a value
- Loop through all child pages
- Display a list of link to those pages, sorted by the value of the propertyAlias
Macro Parameters To Create, for this macro to work:
Alias:startNodeId Name:Select starting page Type:Content Picker
*@
@{ var startNodeId = Model.MacroParameters["startNodeId"]; }
@if (startNodeId != null)
{
@* Get the starting page *@
var startNode = Umbraco.Content(startNodeId);
var selection = startNode.Children.Where("Visible");
if (selection.Any())
{
<ul>
@foreach (var item in selection)
{
<li>
<a href="@item.Url">@item.Name</a>
</li>
}
</ul>
}
}
If I have misunderstood what you are trying to do, then if you can explain it more detailed then I am sure that we can help you.
I can create the above via the partial views no problem.
What I have is a macro with title a field, this macro is added multiple times to a grid layout. I would like to extract all title fields from the macros within the grid and add them to a list.
maybe you should try downloading the Skybrud.Umbraco.GridData NuGet. This gives your grid a model, and then you can iterate through your rows and find the macros you want. I don´t know if it will work, but i think it would be possible.
Access Marco parameters and add to a list
Dear Umbraco Forum Team
Would like to create list from a marco parameter within a macro used multiple times in a grid layout.
Could you advise best practice to achieve this?
Thanks Dibs
Hi Dibs,
You could use this code below, with this you will get the child nodes from the current page, of a changeable source.
If I have misunderstood what you are trying to do, then if you can explain it more detailed then I am sure that we can help you.
Hope this helps,
/Dennis
Cheers Dennis
I can create the above via the partial views no problem.
What I have is a macro with title a field, this macro is added multiple times to a grid layout. I would like to extract all title fields from the macros within the grid and add them to a list.
Hope that makes sense
Hi Dibs,
That make sense now, I am not sure how you can archive this, or if this is possible, perhaps other in the great community, knows if this is possible.
/Dennis
Hi Dibs,
maybe you should try downloading the Skybrud.Umbraco.GridData NuGet. This gives your grid a model, and then you can iterate through your rows and find the macros you want. I don´t know if it will work, but i think it would be possible.
NuGet: https://www.nuget.org/packages/Skybrud.Umbraco.GridData/
Github: https://github.com/skybrud/Skybrud.Umbraco.GridData
But then again. Using Grid to generate a list, is not the finest way. But i´m sure you have your reasons.
/René
Cheers René
I'll have a look at your suggestion. I do have my reasons, they are clients : (
Thanks Dibs
is working on a reply...