@inherits umbraco.MacroEngines.DynamicNodeContext
@using System.Xml.XPath;
@using System.Xml;
@{
var panelBoxes = Model.DescendantsOrSelf("PanelBoxes").Where("Visible");
foreach (var page in panelBoxes.Children.Where("Visible").Any())
{
if (page.NodeTypeAlias = "PanelTextBox")
{
<a href="@page.Url">@page.Name</a>
}
Hello guys. I'm trying to create a right panel, containing different PanelBoxes, therefore I've created a macro that runs through the model and its descendants, and from there I want to get the children of that model, and if it's node type equals a PanelTextBox or a PanelImageBox or a PanelTextAndImageBox I want it to do different stuff.
Now here is my problem. Right now the loading of the macro breaks because of line 7.
foreach (var page in panelBoxes.Children.Where("Visible").Any())
This is the error:
Error Loading Razor Script (file: Panel Boxes) 'umbraco.MacroEngines.DynamicNodeList' does not contain a definition for 'Children'
What else can I do? And if you guys know, please tell me what my problem is! Thank you upfront.
I'm creating this macro to list all of my boxes in a sidebar.
I have 3 different types of boxes, therefore I need to create if-statements to divvi up the markup of every type of box.
So I don't quite understand the "I don't need the other if-statements" :D
Also the problem I have currently isn't really weather or not it works, just that
List<DynamicNode>
Gives me the validation errors:
List : Using the generic type 'System.Collections.Generic.List
DynamicNode : Validation (HTML5): Element 'dynamicnode' is not supported.
I'm pretty sure I'm doing something wrong, but I am clueless.
Sorry, i didnt pay attention to the last part of your code there. So basically you want to display all Nodes present and from there check which docType is being used right ?
Pay no attention to the Frontpage placement, it is essentially done for an easy way to get rid of the 'frontpage' navigation heading.
What i basically want is to get all 'Panel Boxes' children nodes and then run through them in the macro and display them differently based on type. which I think is the correct way i've done it in the if-statements?
I just need a way to get the get the Panel Boxes, so i can traverse them ;/
Yes, every content panel box is created based on different panel box document types.
I've tried the answer above, but what my problem is with that solution, is:
List<DynamicNode>
gives me errors like described 5 posts up, and I can't seem to get it to accept the List collection with DynamicNode as its T argument, do you know why that is?
I wanted to reply to the code sample in your very first post in this thread, to explain your initial error:
var panelBoxes = Model.DescendantsOrSelf("PanelBoxes").Where("Visible");
In the line above, "panelBoxes" is a list of nodes (DyanmicNodeList) which doesn't really have "children" of its own. (An individual node can have "Children", but a list does not have any "Children", just the contents itself of the list itself.) So instead of getting a list, you need to get a node.
Probably what you'll find here is if you have only one type of "PanelBoxes" document, then your list here will only have one item in it anyway. (The container node of all your actual panels.) So you could then say you want the "First" result from this list, which is the individual node we need in order to get to the children you want. For example, try changing to this:
var panelBoxRoot = Model.DescendantsOrSelf("PanelBoxes").First();
foreach (var panelBox in panelBoxRoot.Children.Where("Visible"))
{
...
}
Question: is your document type alias for the panel box root actually named "PanelBoxes"?
Also note, when you "descend" it means you work your way down the tree, so this would still only work if starting at the "Frontpage". The pages such as Articles and Magazines would not find what you're trying to descned into.
A common solution to this problem is to first "ascend" your tree up to the homepage, then descend to find what you're looking for.
var panelBoxRoot = Model.AncestorOrSelf(1).DescendantsOrSelf("PanelBoxes").First();
Final notes: Your line of code here has an error:
if (page.NodeTypeAlias = "PanelTextBox")
Note that this would try to assign a NodeTypeAlias, not compare it. In C#, we need to use double-equal signs when comparing, e.g., if (x == y) and not if (x = y).
And OK one last note, you do not need the "Any()" method inside your "foreach" loop. The "Any()" method returns a true/false boolean, and you can't loop through a boolean result.
It's late and I hope some of this helps, sorry if it causes more confusion! Best of luck to you!
I want to thank you both for your time. I needed this short but crusial journey. I now feel like I understand umbraco a lot more. And thank you Funka, the examples given, made me reach the solution.
Need to get Children from Model
Hello guys. I'm trying to create a right panel, containing different PanelBoxes, therefore I've created a macro that runs through the model and its descendants, and from there I want to get the children of that model, and if it's node type equals a PanelTextBox or a PanelImageBox or a PanelTextAndImageBox I want it to do different stuff. Now here is my problem. Right now the loading of the macro breaks because of line 7.
This is the error:
Error Loading Razor Script (file: Panel Boxes) 'umbraco.MacroEngines.DynamicNodeList' does not contain a definition for 'Children'
What else can I do? And if you guys know, please tell me what my problem is! Thank you upfront.
Hi David,
Try this instead
Hi Fuji, and thanks for the quick response..
I'm sorry to say that I have absolutely no idea what you want me to do XD
Somehow the List gives me an error, and DynamicNode isn't supported. The generic type list T requires 1 type argument and the whole thing won't run.
.
Where the what what equals what in what?
This is my code right now:
This breaks pretty fast, and please dont mind the indention mixup..
Do you have any other suggestions?
Kind Regards
Hi David,
You dont need to make another if to test for the DocType again since your are already listing all docType "PanelBoxes" using Descendants.
Try this and make assuming you are on level 2 here AncestorOrSelf(2).
Hello again, and thank you for your time.
As I see it (correct me if I'm wrong)
I'm creating this macro to list all of my boxes in a sidebar. I have 3 different types of boxes, therefore I need to create if-statements to divvi up the markup of every type of box. So I don't quite understand the "I don't need the other if-statements" :D
Also the problem I have currently isn't really weather or not it works, just that
Gives me the validation errors:
List : Using the generic type 'System.Collections.Generic.List
DynamicNode : Validation (HTML5): Element 'dynamicnode' is not supported.
I'm pretty sure I'm doing something wrong, but I am clueless.
Again thank you so much for your help.
Hi David,
Sorry, i didnt pay attention to the last part of your code there. So basically you want to display all Nodes present and from there check which docType is being used right ?
Can you please show us your content structure ?
Sure, here it is
Pay no attention to the Frontpage placement, it is essentially done for an easy way to get rid of the 'frontpage' navigation heading.
What i basically want is to get all 'Panel Boxes' children nodes and then run through them in the macro and display them differently based on type. which I think is the correct way i've done it in the if-statements?
I just need a way to get the get the Panel Boxes, so i can traverse them ;/
Thanks again!
I guess each of the content listed here are using different DocTyperight ?
Try this
Hey again
Yes, every content panel box is created based on different panel box document types.
I've tried the answer above, but what my problem is with that solution, is:
gives me errors like described 5 posts up, and I can't seem to get it to accept the List collection with DynamicNode as its T argument, do you know why that is?
What version of umbraco are you using and can you please show the whole code in you razor file ?
Hi David,
I wanted to reply to the code sample in your very first post in this thread, to explain your initial error:
In the line above, "panelBoxes" is a list of nodes (DyanmicNodeList) which doesn't really have "children" of its own. (An individual node can have "Children", but a list does not have any "Children", just the contents itself of the list itself.) So instead of getting a list, you need to get a node.
Probably what you'll find here is if you have only one type of "PanelBoxes" document, then your list here will only have one item in it anyway. (The container node of all your actual panels.) So you could then say you want the "First" result from this list, which is the individual node we need in order to get to the children you want. For example, try changing to this:
Question: is your document type alias for the panel box root actually named "PanelBoxes"?
Also note, when you "descend" it means you work your way down the tree, so this would still only work if starting at the "Frontpage". The pages such as Articles and Magazines would not find what you're trying to descned into.
A common solution to this problem is to first "ascend" your tree up to the homepage, then descend to find what you're looking for.
Final notes: Your line of code here has an error:
Note that this would try to assign a NodeTypeAlias, not compare it. In C#, we need to use double-equal signs when comparing, e.g.,
if (x == y)
and notif (x = y)
.And OK one last note, you do not need the "Any()" method inside your "foreach" loop. The "Any()" method returns a true/false boolean, and you can't loop through a boolean result.
It's late and I hope some of this helps, sorry if it causes more confusion! Best of luck to you!
I want to thank you both for your time. I needed this short but crusial journey. I now feel like I understand umbraco a lot more. And thank you Funka, the examples given, made me reach the solution.
Thank you thank you thank you.
is working on a reply...