Locator Tool - getChild of getChild?
I've attempted to use the Locator Tool to set it to the current page, then drill down through the xml using getStructuredDataNode and getChild. However, it appears I can only grab data one level deep.
#set ( $page = $_.locatePage($currentPagePath,
$currentPageSiteName))
#set ( $main =
$page.getStructuredDataNode("main"))
I can get <content1>
data using
#set ( $content1 = $main.getChild('content1'))
<main>
....<content1>
I can't get <content2>
data using
#set ( $content2 =
$content1.getChild('content1'))
<main>
....<content1>
........<content2>
Am I missing something easy, or can the Locator Tool only go one level?
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 19 Mar, 2014 06:42 PM
Hi,
I was able to successfully traverse 3 levels in my local Cascade Server 7.10 instance, so this should definitely be possible.
When you have a moment, please provide the XML of the page's Data Definition so I can take a look at how the structured data looks.
Please let me know if you have any questions.
Thanks!
2 Posted by johjacb on 25 Mar, 2014 05:52 PM
Hi Ryan,
Thanks for the reply. I've attached an XML document. I'm trying to access the data on say, line 65. How would I do that using the Locator Tool?
Thanks
3 Posted by Ryan Griffith on 25 Mar, 2014 08:20 PM
Hi,
Thank you for providing the XML sample.
Looking over your XML, it appears you are attempting to access the contents coming from a Block chooser. The
getChild()
method will not work with asset choosers, only text-based fields. You would need to use the asset type's API (in this case a Block) to access the contents within.I will make a note to look into this a bit more tomorrow morning and try to get back to you with some example code to get you started.
Please let me know if you have any questions.
Thanks!
4 Posted by Ryan Griffith on 27 Mar, 2014 01:03 PM
Hi,
My apologies for not responding sooner.
Using the sample XML you provided, here is a snippet that would allow you to traverse into the
form-block
chooser's content to access theformhash
field:So, I believe what you'll want to do while you're traversing is to either check if
getChildren
is null after callinggetStructuredDataNode()
, or check ifasset
is null, to see if you are dealing with an asset or a group/text field. The following would be an example of checking ifasset
is not null:Please let me know if you have any questions.
Thanks!
5 Posted by johjacb on 27 Mar, 2014 01:38 PM
Thanks for the reply.
I was missing the
.asset
bit in getting the block contents via.getStructuredDataNode
.Thanks for your assistance.
6 Posted by Ryan Griffith on 27 Mar, 2014 02:09 PM
Not a problem at all, when I was testing originally I had done the same exact thing.
I'm going to go ahead and close this discussion, please feel free to comment or reply to re-open if you have any additional questions.
Have a great day!
Ryan Griffith closed this discussion on 27 Mar, 2014 02:09 PM.