Moved Format to another Region and now fails

Rick's Avatar

Rick

25 Jul, 2016 07:10 PM

I had a format in the Default region that basically dumped the WYSIWYG control as well as created a Left Nav Menu. It all worked. Really. :)

But as I've learned more and more about how Cascade should work, I realized I should break that into two regions and did that. The Wysy and left menu didn't share any code, so it was easy to split the two. I left the Wysi-only bit in the Default and created a new Format to handle the Left Nav stuff. I applied it to the newly created Region.

And now it doesn't work! I am getting invalid "SelectSingleNode" errors in the initial reads.

I've been scouring this site, Google, etc all day trying to figure it out. I see many references to calling pages, and getStructuredNode, but I cannot get any of them to work.

In a nutshell, all I am trying to do at this point is make the initial lines *that did work* when the format was on the Default region, work when they are in a format applied to a different region. Here's one:

#set ($navPath = $_XPathTool.selectSingleNode($contentRoot,"/system-data-structure/leftNavBlock/path"))

Thanks

  1. Support Staff 1 Posted by Tim on 25 Jul, 2016 07:29 PM

    Tim's Avatar

    Hi Rick,

    By default, the DEFAULT region will return the current page's Structured Data so that it is readily available to be transformed by a Format. This data comes in the form:

    <system-data-structure>
    ...page content here...
    </system-data-structure>
    
    which is why your XPath statement in your Format:
    #set ($navPath = $_XPathTool.selectSingleNode($contentRoot,"/system-data-structure/leftNavBlock/path"))
    
    worked in the DEFAULT region.

    All other regions will not automatically provide the page's data to you. Instead, you have to create an Index Block that basically indexes the current page so that you can get to the data you're looking to transform. Check out this article for an example of how to create a 'current page Index Block'. Once you have this Index Block created, you can do the following:

    • Click Edit on your Format
    • In the Preview Options drop down menu, select Block
    • In the Block Chooser, select your new 'current page' Index Block
    • In the Context Page field, select one of the Pages you're trying to get this to work on
    • After you select a Context Page, you should see content rendered in the preview to show you the data available to you
    • You'll see that the XML now looks like:
      <system-index-block>
      ...
      <system-data-structure>
      ...
      </system-data-structure>
      ...
      </system-index-block>
      
    • Since the XML tree structure is different, you can modify your Format in this interface such to match it up

    For example, I'm guessing you'll need to change:

    #set ($navPath = $_XPathTool.selectSingleNode($contentRoot,"/system-data-structure/leftNavBlock/path"))
    
    to something like:
    #set ($navPath = $_XPathTool.selectSingleNode($contentRoot,"/system-index-block/calling-page/system-page/system-data-structure/leftNavBlock/path"))
    

    It seems like a lot, but it's not bad once you get the hang of it. Let me know if this helps at all!

  2. 2 Posted by Rick on 25 Jul, 2016 07:50 PM

    Rick's Avatar

    Thank you - that is definitely very informative!

    Unfortunately it only worked to a point. Everything went exactly how you said it would, until it got to the XML preview. The XML was there as expected, but it just sort of stopped.

    Whereas the expected path was: /system-index-block/calling-page/system-page/system-data-structure/leftNavBlock/path

    The actual tree went no lower than: /system-index-block/calling-page/system-page

    That level did have some page-level attributes on it, but there was no system-data-structure to go lower.

    (Edit: I replied once but not sure it actually worked. So if this is a duplicate post, I apologize)

  3. Support Staff 3 Posted by Tim on 25 Jul, 2016 07:57 PM

    Tim's Avatar

    That level did have some page-level attributes on it, but there was no system-data-structure to go lower.

    Gotcha. Edit your Index Block and make sure the following options are checked:

    • Indexed Asset Content: Regular Content
    • Page XML: Render page XML inline

    Let me know if one of those was missing and whether or not you can see the info now.

    Thanks

  4. 4 Posted by Rick on 25 Jul, 2016 08:02 PM

    Rick's Avatar

    Yep - I skipped the Page XML part. User Error (surprise!) :)

    So now in the preview, I got what I expect to get. OK, what you told me to expect to get :)

    However, I am still getting the following error:

    An error occurred: Could not transform with Script format "DemoFolder/Formats/ICL Left Nav": org.apache.velocity.exception.MethodInvocationException: Invocation of method 'selectSingleNode' in class org.jdom.xpath.JaxenXPath threw exception java.lang.NullPointerException at velocityTransform-1469476836377[line 8, column 30]

    Does that index block get attached to the page someplace? Or is it only used as a preview item when looking at the format?

  5. Support Staff 5 Posted by Tim on 25 Jul, 2016 08:20 PM

    Tim's Avatar

    Does that index block get attached to the page someplace? Or is it only used as a preview item when looking at the format?

    Yes. If you're getting the error you mentioned when viewing the Page itself, that makes sense because you haven't attached it yet. To attach it, you'll want to edit the Configuration for this Page, then assign your 'current page' Index Block to the same region where your Format is currently applied.

    As a side note, if you go through the preview steps again for your Format, you'll see that there is a Test Format button. This runs the transformation against the XML that you see in the preview, so it's very useful for troubleshooting without having to apply the Block to the Page first.

    I'll wait to hear back and we can go from there.

    Thanks

  6. 6 Posted by Rick on 25 Jul, 2016 08:29 PM

    Rick's Avatar

    Ugh. Yeah. I should have known that. /facepalm.

    Looks like it is working now. Thank you very much!

  7. Support Staff 7 Posted by Tim on 25 Jul, 2016 08:34 PM

    Tim's Avatar

    Awesome.

    You'll basically repeat this process for any other regions (aside from DEFAULT) where you need to output data from the page itself. You may also be interested in learning about the Locator Tool which can eliminate the need for having Index Blocks.

    Have a good one, Rick!

  8. Tim closed this discussion on 25 Jul, 2016 08:34 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