Forcing TAL to render mismatched tags
Today I installed Google website optimizer for a Plone site. This tool requires the use of a </noscript> tag in order to designate the end of a block that may be used in experiments. Unfortunately, if you try to insert this in a Zope page template you’ll see something like this:
Compilation failed zope.tal.htmltalparser.NestingError: No tags are open to match </noscript>, at line 2, column 1
You can work around this using the following idiom:
<tal:block tal:content="structure string:</noscript>"/>
This bypasses TAL compilation by parsing the </noscript> as a string, then inserts it into the template as HTML structure. The angle brackets are written as HTML entities so that the template has a chance of passing XML validation.
Credit to Darryl Dixon via #plone on IRC, and my colleague Jon Baldivieso for the HTML entities suggestion. Thanks!
I actually really like this approach and would try this way. I like seeing the ‘forceinvalid’ so you know exactly what is being accomplished on the line.
<tal:forceinvalid content=”structure string:</noscript>”/>
Adam said this on November 12th, 2008 at 7:31 am
Awesome! Thanks for this.
Eric Steele said this on November 12th, 2008 at 8:30 am
very cool and interesting.
Rob Porter said this on November 14th, 2008 at 8:13 am