Use current page data definition fields inside a block.

latorresescobedo's Avatar

latorresescobedo

12 May, 2016 03:42 PM

I currently have a block "header", which contains a title.
Also I have a page with a data definition that defines such title.

how can I access the current page data definition while im inside the header block?

I have tried the following:
#set( $content = $_XPathTool.selectSingleNode($contentRoot, "/system-data-structure"))
#set( $content = $_XPathTool.selectSingleNode($contentRoot, "/system-folder[system-page[@current]]"))

but it seems I can only access the data definition for the block.
is it possible or I am doing thigs wrong?

  1. 1 Posted by Wing Ming Chan on 12 May, 2016 04:04 PM

    Wing Ming Chan's Avatar

    First, is the header block attached to the page in question? If not, how are the two related? If so, is the block attached to a region or a block chooser?

    Wing

  2. 2 Posted by latorresescobed... on 12 May, 2016 04:05 PM

    latorresescobedo's Avatar

    yes the block is attached to the page in question. and the block belongs to a region.

  3. 3 Posted by Wing Ming Chan on 12 May, 2016 04:15 PM

    Wing Ming Chan's Avatar

    Since the block is attached to a region, you loss the context of the hosting page. If you look at $contentRoot, it only contains the XML of the block, not anything related to the hosting page. You will have to use the $currentPage variable to retrieve page content, utilizing the Cascade API. Another option is to attach the block to a block chooser in the page instead. Then you will have to process the block while you are processing the page. The context of the page is given.

    Wing

  4. 4 Posted by latorresescobed... on 12 May, 2016 04:30 PM

    latorresescobedo's Avatar
    $currentPage.getStructuredDataNode("title")
    

    this did the trick, thank you.

  5. Ryan Griffith closed this discussion on 12 May, 2016 05:35 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