Question about macros to list children / filter children.
Hi, I have two questions about macros meant to list children elements. It is slowling me down on my blog unfortunately :( So I figured I should ask for advice.
First, with my current macro, I list children just fine, unless there is only one, and then it does not render anything. I basically have a parent element with 5 children, but usually only one or two of them will be published at the same time. When it is one the issue occurs. Could anyone have a peek at the following code and let me know if they spot something obvious?
@{
foreach (var page in CurrentPage.Children.Where("Visible"))
{
Secondly, is there an easy way to let's say render only 5 children element on one page (.Take() I presume),and then the next 5 on a second page using the same node/template?
Please let me know if you have any thoughts. Thanks in advance.
When there is only one node published is that one node then actually visible? Or has it been hidden for some reason? If so that's why it does not show.
In regards to your second question...how are the nodes you want to list selected? Are they selected using multinode picker and picked on a certain node?
I think the proper way to do it is to have a multinode picker setup on each node where you can specifically pick 5 different nodes for each page and then have a make just loop through the nodes selected on each node.
I think you ask for paging with 5 items per page. For example you can use @foreach (var item in items.Skip((page - 1) * pageSize).Take(pageSize)) to step forward. Below you find an example I use. In your case you should use pageSize = 5;. Good Luck!
Jan, yes, for some reason when it is only one child, even though it is published and I can access it my macros does not render it unfortunately. For my second question, they are children articles of my blog, I have like 80 of them, I don't use a node picker for this.
First problem is now sorted. Seems like the first child had to be republished, it did the trick. Funny enough it still displayed when more than one was present.. hmm.
Question about macros to list children / filter children.
Hi, I have two questions about macros meant to list children elements. It is slowling me down on my blog unfortunately :( So I figured I should ask for advice.
First, with my current macro, I list children just fine, unless there is only one, and then it does not render anything. I basically have a parent element with 5 children, but usually only one or two of them will be published at the same time. When it is one the issue occurs. Could anyone have a peek at the following code and let me know if they spot something obvious?
@{ foreach (var page in CurrentPage.Children.Where("Visible")) {
} }
Secondly, is there an easy way to let's say render only 5 children element on one page (.Take() I presume),and then the next 5 on a second page using the same node/template?
Please let me know if you have any thoughts. Thanks in advance.
Cheers,
Alex.
Hi Alex
When there is only one node published is that one node then actually visible? Or has it been hidden for some reason? If so that's why it does not show.
In regards to your second question...how are the nodes you want to list selected? Are they selected using multinode picker and picked on a certain node?
I think the proper way to do it is to have a multinode picker setup on each node where you can specifically pick 5 different nodes for each page and then have a make just loop through the nodes selected on each node.
Does this make sense?
/Jan
Hi Alex,
I think you ask for paging with 5 items per page. For example you can use
@foreach (var item in items.Skip((page - 1) * pageSize).Take(pageSize))
to step forward. Below you find an example I use. In your case you should usepageSize = 5
;. Good Luck!Thank you for the piece of code Martin.
Jan, yes, for some reason when it is only one child, even though it is published and I can access it my macros does not render it unfortunately. For my second question, they are children articles of my blog, I have like 80 of them, I don't use a node picker for this.
First problem is now sorted. Seems like the first child had to be republished, it did the trick. Funny enough it still displayed when more than one was present.. hmm.
is working on a reply...