Can't get the page elements
I'm sure I'm doing something stupid here, but I can't get the page elements for the life of me. I have a very simple XML index of a folder with a few pages in it. The highest level tag is "system-index-block", with "system-page" elements underneath it (they're the next level down). Why does this code below return nothing? I've tried the selectNodes line with a slash before system-page, and without. Neither return anything. Can you tell me what I'm doing wrong, and why it doesn't work? Thanks.
## Abstract out the "system-index-block" node
#set ($sib = $_XPathTool.selectSingleNode($contentRoot, "/system-index-block"))
## Gather "system-page" nodes
#set ($items = $_XPathTool.selectNodes($sib, "/system-page"))
Item size is $items.value <br />
## Make the menu
#if ($items.size > 0)
## Loop through pages
#foreach ($item in $items)
$item.getAttribute("name") <br />
#end
#end
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 Wing Ming Chan on 19 Jun, 2015 11:10 PM
Hi,
Try removing the slash right before 'system-page'.
Wing
2 Posted by Ryan Griffith on 22 Jun, 2015 12:16 PM
Also, if you are attempting to get the system name of the pages, you will want to change the following:
to:
Please let me know if you have any questions.
Thanks!
3 Posted by webadmin on 22 Jun, 2015 01:45 PM
Like I said, I already tried it without the slash, and it didn't work that way either. I just tried it again to verify. As for the getChild part, the $items variable isn't loading at all, so it wouldn't matter about that. I'm attaching the XML I'm trying to read. Maybe there's something weird about it.
4 Posted by Ryan Griffith on 22 Jun, 2015 02:41 PM
Just noticed your
#if
statement is incorrect. When you have a moment, try changing it to the following:So, with all of the changes:
Please let me know if you have any questions.
Thanks!
5 Posted by webadmin on 22 Jun, 2015 02:53 PM
That did make it loop correctly, but why does $items.value not show anything? Isn't that supposed to output the entirety of the variable? If $items exists, shouldn't I get a big list of text out of it?
6 Posted by Ryan Griffith on 22 Jun, 2015 05:28 PM
Thank you for following up, I am glad to hear the adjustment did the trick.
.value
is shorthand for agetValue()
method on the object you are invoking it on, which in this case would most likely be a JDOM Element. If you want to dump the contents of the element, I would recommend something more like:Please let me know if you have any questions.
Thanks!
Ryan Griffith closed this discussion on 30 Jun, 2015 07:09 PM.