velocity formats on a text block

Kris's Avatar

Kris

17 Mar, 2016 09:58 PM

I am attempting to apply this format:
[code]
##test to see if page has data
#if (!$_PropertyTool.isNull($contentRoot))
    ##retrieve the full page data
    #set ( $h1 = $_XPathTool.selectSingleNode($contentRoot,"/block-xhtml") )
    
    #if ($h1.value != '')
        <div class="page-header">
            <h1 class="container">$_EscapeTool.xml($h1.value)</h1>
        </div>
    #end
#end
[/code]

to a text block:
[code]
<block-xhtml>About Us</block-xhtml>
[/code]

When I click "test format" I get what I expect:
[code]
        <div class="page-header">
            <h1 class="container">About Us</h1>
        </div>
[/code]

When I use the same format on a block assigned via a configuration set I get:
[code]
        <div class="page-header">
            <h1 class="container">$_EscapeTool.xml($h1.value)</h1>
        </div>
[/code]

as if the h1 value is not defined.

  1. Support Staff 1 Posted by Tim on 18 Mar, 2016 03:16 PM

    Tim's Avatar

    Hi Kris,

    Thanks for including all of those details. To clarify, is it safe for me to say that your Text Block really only contains the text 'About Us'? You mentioned that it contains:

    <block-xhtml>About Us</block-xhtml>
    
    but I'm assuming you're going by what you're seeing in the Test Format interface when you select that Block.

    If that is indeed the case, the reason for those added <block-xhtml> tags is so that the content is valid XML (because without them, there wouldn't be a root element). This makes your Format work in the Test Format interface because you're looking for the child element <block-xhtml> from the contentRoot here:

        #set ( $h1 = $_XPathTool.selectSingleNode($contentRoot,"/block-xhtml") )
    
    In the context of a Page, however, the <block-xhtml> element doesn't exist because it is assumed that the section of the Page you are placing it into is already well formed. So, if you're simply trying to output the contents of whatever is in your Text Block, try changing this line to something like:
        #set ( $h1 = $_XPathTool.selectSingleNode($contentRoot,"node()") )
    
    and let me know if that helps.

    Thanks!

  2. 2 Posted by Kris on 18 Mar, 2016 03:29 PM

    Kris's Avatar

    Thanks Tim, that was indeed what the issue was.

  3. Support Staff 3 Posted by Tim on 18 Mar, 2016 03:32 PM

    Tim's Avatar

    Cool! Thanks for the update, Kris! Glad that helped.

    Have a good one.

  4. Tim closed this discussion on 18 Mar, 2016 03:32 PM.

Discussions are closed to public comments.
If you need help with Cascade CMS please 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

 

26 Aug, 2016 01:19 PM
25 Aug, 2016 03:02 PM
25 Aug, 2016 12:50 PM
24 Aug, 2016 08:43 PM
24 Aug, 2016 07:20 PM
21 Aug, 2016 01:20 PM