Get a Page data definition date using the Locator tool

ediego's Avatar

ediego

02 Jun, 2016 01:54 PM

I am trying to get the data defintion contents from a page using the Locator tool, but I can't seem to figure it out. I'm trying to get the value of the enabled checkbox in the data definition for the page. I've tried a few metohs, but can't seem to figure it out. I am also attaching the data definition for te page.
I have the following code:
#set ($xPage = $_.locatePage("/_cascade/site-assets/sticky-buttons/sticky-buttons", $currentPage.siteName))
$_PropertyTool.outputProperties($xPage)
#set ($xContent = $xPage.getStructuredDataNode("sticky-buttons-group/enabled"))
#set ($sEnabled = $xPage.getStructuredDataNode("sticky-buttons-group/enabled").textValue)
$_PropertyTool.outputProperties($xContent)

Enabled: $xContent.textValue
Enabled: $sEnabled

Here is what gets output:
Object type: com.hannonhill.cascade.api.adapters.PageAPIAdapter
Properties:
 - lastPublishedBy: String
 - lastModified: Date
 - link: String
 - dataDefinitionPath: String
 - identifier: PathIdentifier
 - parentFolder: Folder
 - getStructuredDataNode(String): StructuredDataNode
 - isUserCanWrite(String): boolean
 - structuredData: StructuredDataNode[]
 - currentUserCanWrite: boolean
 - createdOn: Date
 - metadata: Metadata
 - folderOrder: int
 - parentFolderIdentifier: PathIdentifier
 - createdBy: String
 - identifer: Identifier
 - lastPublishedOn: Date
 - path: String
 - lastModifiedBy: String
 - shouldBePublished: boolean
 - currentUserCanRead: boolean
 - isUserCanRead(String): boolean
 - hideSystemName: boolean
 - siteName: String
 - shouldBeIndexed: boolean
 - siteId: String
 - xHTMLAsXMLElement: Element
 - name: String
 - xHTML: String
 - getStructuredDataNodes(String): StructuredDataNode[]

Object type: com.hannonhill.cascade.api.adapters.StructuredDataNodeAPIAdapter
Properties:
 - asset: boolean
 - allowCustomValues: boolean
 - textValues: String[]
 - assetIdentifier: PathIdentifier
 - getChildren(String): StructuredDataNode[]
 - children: StructuredDataNode[]
 - getChild(String): StructuredDataNode
 - group: boolean
 - textValueAsXMLElement: Element
 - asset: FolderContainedAsset
 - textNodeOptions: TextNodeOptions
 - textValue: String
 - text: boolean
 - identifier: String
 - group: StructuredDataNode[]

Enabled: $xContent.textValue
Enabled: $sEnabled

  1. 1 Posted by Ryan Griffith on 02 Jun, 2016 02:23 PM

    Ryan Griffith's Avatar

    Hi Emil,

    For checkbox, radio and multi-select fields, you will want to use is the textValues property for the field, which will return an array of each checked/selected value. You can use the Property Tool to see the available properties for the StructuredDataNodeAPIAdapter.

    Note: there is a known defect in which the first item in the returned array is empty, so the array basically starts at index 1. The following should return your value:

    $xPage.getStructuredDataNode("sticky-buttons-group/enabled").textValues.get(1)
    

    Also, you may want to check the size of the array prior to attempting to use .get(1) to avoid an IndexOutOfBounds error. Because of the known defect, you basically need to check to see if the size is greater that 1 (or equal to 2 if you know for a fact there will only ever be one checkbox):

    #set ($sEnabled = $xPage.getStructuredDataNode("sticky-buttons-group/enabled").textValues)
    #if ($sEnabled.size() == 2)
        ## ... do something with the value "Yes"
        $sEnabled.get(1)
    #end
    

    Please let me know if you have any questions.

    Thanks!

  2. 2 Posted by ediego on 02 Jun, 2016 06:05 PM

    ediego's Avatar

    thanks. that helped get the data for that field.

    Are there any tricks/caveats to getting the data from a Page asset chooser?

  3. 3 Posted by Ryan Griffith on 02 Jun, 2016 08:37 PM

    Ryan Griffith's Avatar

    Thank you for following up, Emil. Glad to hear the snippet helped out.

    Are there any tricks/caveats to getting the data from a Page asset chooser?

    When you use the Cascade API to access the asset chooser field, you will be given direct access to the page object itself. From there, you simply access it's structured data (or any of its data) just like you are doing now with your $xPage variable.

    Please let me know if you have any questions.

    Thanks!

  4. 4 Posted by ediego on 03 Jun, 2016 01:36 PM

    ediego's Avatar

    I think i have this mostly figured out. thanks. Still having one issue though. I have a text field that I am using to store an external url. This url can have a variety of different characters lie the following:
    http://pages.connect.miami.edu/MailingList?utm_source=stickymenu&utm_medium=website&utm_campaign=Left%20Hand%20Sticky%20Nav

    When i try displaying the URL value on the output I get the following error from the CMS:
    An error occurred: Could not transform with Script format "_cascade/formats/um-generic-website/primary-landing-page-main-slideshow-v3": Error on line 72: The reference to entity "utm_medium" must end with the ';' delimiter.

    I've tried using the EscapeTool.xml function, I've tried using the protect directive, but no matter what I do i can't get past the error.

    any ideas?

  5. 5 Posted by ediego on 03 Jun, 2016 01:52 PM

    ediego's Avatar

    never mind, I answered my own question.

    I wrapped everything in
    <![CDATA[#protect

    and it worked.

  6. 6 Posted by Ryan Griffith on 03 Jun, 2016 07:56 PM

    Ryan Griffith's Avatar

    Thank you for following up, Emil. I am glad to hear you were able to resolve your issue.

    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 03 Jun, 2016 07:56 PM.

Comments are closed, but you can 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