Locator Tool - getChild of getChild?

johjacb's Avatar

johjacb

18 Mar, 2014 03:07 PM

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?

  1. 1 Posted by Ryan Griffith on 19 Mar, 2014 06:42 PM

    Ryan Griffith's Avatar

    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. 2 Posted by johjacb on 25 Mar, 2014 05:52 PM

    johjacb's Avatar

    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. 3 Posted by Ryan Griffith on 25 Mar, 2014 08:20 PM

    Ryan Griffith's Avatar

    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. 4 Posted by Ryan Griffith on 27 Mar, 2014 01:03 PM

    Ryan Griffith's Avatar

    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 the formhash field:

    #set ( $page = $_.locatePage($currentPagePath, $currentPageSiteName))
    #set ( $formblock = $page.getStructuredDataNode("form-block"))
    #set ( $formhash = $formblock.asset.getStructuredDataNode("formhash") )
    $formhash.textValue
    

    So, I believe what you'll want to do while you're traversing is to either check if getChildren is null after calling getStructuredDataNode(), or check if asset is null, to see if you are dealing with an asset or a group/text field. The following would be an example of checking if asset is not null:

    #if ($formblock.asset)
       ... code for an asset here ...
    #else
       ... code for a structured data node here ...
    #end
    

    Please let me know if you have any questions.

    Thanks!

  5. 5 Posted by johjacb on 27 Mar, 2014 01:38 PM

    johjacb's Avatar

    Thanks for the reply.

    I was missing the .asset bit in getting the block contents via .getStructuredDataNode.

    Thanks for your assistance.

  6. 6 Posted by Ryan Griffith on 27 Mar, 2014 02:09 PM

    Ryan Griffith's Avatar

    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!

  7. Ryan Griffith closed this discussion on 27 Mar, 2014 02:09 PM.

Comments are currently closed for this discussion. You can start a new one.

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