using locateBlock to select node value

Prashanth's Avatar

Prashanth

23 Oct, 2015 09:40 PM

Hi,
I am trying to use locateblock to get value from xhtml/DD block. Could you please provide me script to achieve this.
My Block

<?xml version="1.0" encoding="UTF-8"?>
<system-data-structure>
    <image1 type="file">
        <content />
        <path>/images/accreditation.jpg</path>
        <dynamic-metadata>
            <name>display-in-nav</name>
            <value>Yes</value>
        </dynamic-metadata>
        <link>site://root/images/accreditation.jpg</link>
        <site>root</site>
        <name>accreditation.jpg</name>
    </image1>
    <image2 type="file">
        <content />
        <path>/images/accreditation.jpg</path>
        <dynamic-metadata>
            <name>display-in-nav</name>
            <value>Yes</value>
        </dynamic-metadata>
        <link>site://root/images/accreditation.jpg</link>
        <site>root</site>
        <name>accreditation.jpg</name>
    </image2>
    <image3 type="file">
        <content />
        <path>/images/accreditation.jpg</path>
        <dynamic-metadata>
            <name>display-in-nav</name>
            <value>Yes</value>
        </dynamic-metadata>
        <link>site://root/images/accreditation.jpg</link>
        <site>root</site>
        <name>accreditation.jpg</name>
    </image3>
</system-data-structure>

My format

#set ( $imageUploader = $_.locateBlock("/news/imageuploader",$currentPageSiteName )) ## Successfully loaded
How do I navigate from here and fetch <link> node value ?

Thanks,
Prashanth

  1. 1 Posted by Wing Ming Chan on 23 Oct, 2015 11:23 PM

    Wing Ming Chan's Avatar

    Since you have chosen to use the Locator tool, the block XML is no longer available to you. Instead, you need to work with structured data. See my discussion on Accessing system-data-structure with the Locator Tool.

    I am also working on Lesson 10: Structured Data and Metadata, taking about this, in my tutorial site.

    Wing

  2. 2 Posted by Ryan Griffith on 26 Oct, 2015 02:05 PM

    Ryan Griffith's Avatar

    Hi Prashanth,

    As Wing mentioned, you will need to use the Cascade API to access your Block's structured data. In your case the following would give you access to each individual file chooser:

    • $imageUploader.getStructuredDataNode("image1")
    • $imageUploader.getStructuredDataNode("image2")
    • $imageUploader.getStructuredDataNode("image3")

    Alternatively, you could loop over all of the nodes assuming you need to access each of the choosers and the block's data definition won't be changing:

    #foreach ( $imageField in $imageUploader.structuredData)
      #if (!$_PropertyTool.isNull($imageField.asset))
        $imageField.asset.link
      #end
    #end
    

    Please let me know if you have any questions.

    Thanks!

  3. 3 Posted by Prashanth on 26 Oct, 2015 02:18 PM

    Prashanth's Avatar

    Thank you Wing & Ryan. It worked.
    To get <link> value, I used,

    $imageUploader.getStructuredDataNode("image1").asset.link
    $imageUploader.getStructuredDataNode("image2").asset.link
    $imageUploader.getStructuredDataNode("image3").asset.link

    (foreach loop also worked as Ryan suggested)

    Thanks,
    Prashanth

  4. 4 Posted by Ryan Griffith on 26 Oct, 2015 02:22 PM

    Ryan Griffith's Avatar

    Thank you for following up, Prashanth, I am glad to hear you were able to get your Format working.

    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!

  5. Ryan Griffith closed this discussion on 26 Oct, 2015 02:22 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