[ZPT] Idea for variable interpolation
Evan Simpson
evan@digicool.com
Tue, 15 May 2001 23:38:13 -0400
A couple of people have run into pain while trying to interpolate variables
into text in places where a <span> or <div> doesn't work well (or at all).
A good example of this is the inside a <script> or <style> tag. There are a
few possible ways of handling this:
1. Pull the offending text into a DTML Method, and use
tal:replace="structure here/theMethod" to put it back. This has the
disadvantage of making the template source diverge from the rendered page.
Since a <script> would likely be inert in an editor anyway, this may not be
a problem for scripts, but <style> is very much a part of the page's
appearance.
2. Pull the offending text into a DTML Method and somehow allow the Method
(or a controlling Script that provides edit-time defaults) to act as a macro
source.
3. Come up with a better way to interpolate variables into text.
I have an idea for #3, but I don't know how reasonable it would be for the
uses to which you folks would be puttting it. Basically, we would make a
new TAL statement that does search-and-replace on the contents of its
statement tag. For example:
<script tal:put="NAME string:'$dir/dot.jpg'; IMG here/image_name">
var img = window.IMG;
img.src = NAME;
</script>
Naturally, you would need to be careful with the strings you chose as
placeholders, and in my example the syntax implies that a placeholder
couldn't contain whitespace.
Cheers,
Evan @ digicool