Using .size() to check folder contents
I have a button on my folder that are a plus and minus. When you click the plus , the contents of the folder is shown; when you click the minus the contents of the folder gets hidden
I'm wanting to remove this button if there is only one item in the folder.
So I thought using the .size() method would work for this, but I'm not having any luck.
Basically if there is only one item in this folder don't show the button at all. Any help would be great. I have attached part of my code that I'm having problems with.
Thanks.
- size-code.txt 1.7 KB
Discussions are closed to public comments.
If you need help with Cascade CMS please
start a new discussion.
Keyboard shortcuts
Generic
? | Show this help |
---|---|
ESC | Blurs the current field |
Comment Form
r | Focus the comment reply box |
---|---|
^ + ↩ | Submit the comment |
You can use Command ⌘
instead of Control ^
on Mac
1 Posted by Ryan Griffith on 07 Apr, 2016 02:27 PM
Hi,
I believe instead of checking
$item.size()
you would want to either check$rootItems.children.size()
or use$foraech.count
(number of items to iterate in the loop).Please let me know if you have any questions.
Thanks!
2 Posted by nicban on 07 Apr, 2016 03:49 PM
Hi Ryan,
I did try your solutions with no luck. I have include my whole code
Here a little more background information
So I created this navigation. I have a base folder with multiple site folders Inside each site folder are sub folders. These sub folder are my navigation.
I have one folder with one page in it, its the index page.
So since this has only one item in my folder, I don't want this plus button showing on the navigation indicating there is something more in the folder.
When I try both solutions I either get all buttons showing or none.
3 Posted by Ryan Griffith on 07 Apr, 2016 05:49 PM
Thank you for providing your full code, definitely helpful.
I believe what you will want to do is tweak the conditional to
$item.children.size()
because that is what you are looping over directly after.I also want to mention you can run into a case where children is greater than 0, but there are no items to display. This is because you are checking for the rblShowInNav Dynamic Metadata field within the loop, after the children size is checked. Your best bet to avoid this would be to loop over the children and save them to a temporary array if the metadata field's value is Yes. Then, you would check the size of your temporary array and loop over that instead. Consider the following snippet:
Please let me know if you have any questions.
Thanks!
Tim closed this discussion on 27 Apr, 2016 08:42 PM.