A while back, I was writing about the Dreamweaver Double Lookup technique for Tridion templating.
I was however struggling with escaping the DWT notation, notably with JSTL Expression Language syntax. The EL syntax is the same with DWT's for outputting variables and expressions: ${ expression }
I used to output EL expressions as $[ expression ] and then have a TBB to replace the square brackets with curly braces.
Finally, I found out today not one, but two ways to escape the DWT syntax ${}. Both following expressions output ${'Hello, world'}
Now you know... :)
But, wait... we are not there yet! This approach above, only works from a Dynamic CT or a Page Template. The embedded CT will not work as expected. The reason is the two DWT TBBs that get executed with embedded CPs: one for the CT itself and the second for the PT that outputs the Component Presentation.
An embedded CT that contains the code ${'$'}{'Hello, world'} produces DWT output ${'Hello, world'} and when the PT executes, it generates the final output Hello, world
So the solution is to encode the string twice (you're heading now for a headache) :)
The embedded CT DWT: ${'$'}{'${'$'}'}{'Hello, world'} - I'll explain below
The CT output (i.e. input for PT): ${'$'}{'Hello, world'} - expression explained above
The PT output: ${'Hello, world'} - the desired JSTL EL output
A similar notation for the CT is: @@'$'@@{'@@'$'@@'}{'Hello, world'}
The way this works:
I was however struggling with escaping the DWT notation, notably with JSTL Expression Language syntax. The EL syntax is the same with DWT's for outputting variables and expressions: ${ expression }
I used to output EL expressions as $[ expression ] and then have a TBB to replace the square brackets with curly braces.
Finally, I found out today not one, but two ways to escape the DWT syntax ${}. Both following expressions output ${'Hello, world'}
- ${'$'}{'Hello, world'}
- @@'$'@@{'Hello, world'}
The trick in both cases is to escape the output of the dollar symbol ($) by using it as String parameter in the surrounding @@ @@ or ${ }. What follows is the normal unescaped {'Hello, world'} output.
Now you know... :)
But, wait... we are not there yet! This approach above, only works from a Dynamic CT or a Page Template. The embedded CT will not work as expected. The reason is the two DWT TBBs that get executed with embedded CPs: one for the CT itself and the second for the PT that outputs the Component Presentation.
An embedded CT that contains the code ${'$'}{'Hello, world'} produces DWT output ${'Hello, world'} and when the PT executes, it generates the final output Hello, world
So the solution is to encode the string twice (you're heading now for a headache) :)
The embedded CT DWT: ${'$'}{'${'$'}'}{'Hello, world'} - I'll explain below
The CT output (i.e. input for PT): ${'$'}{'Hello, world'} - expression explained above
The PT output: ${'Hello, world'} - the desired JSTL EL output
A similar notation for the CT is: @@'$'@@{'@@'$'@@'}{'Hello, world'}
The way this works:
- ${'$'} or @@'$'@@ outputs a dollar sign ($);
- {' outputs normally a open curly brace and an apostrophe;
- ${'$'} or @@'$'@@ outputs a dollar sign ($) again;
- '} outputs normally an apostrophe and a close curly brace;
- {'Hello, world'} outputs normally as-is;
Comments