[ZPT] Idea for variable interpolation

richard@bizarsoftware.com.au richard@bizarsoftware.com.au
Wed, 16 May 2001 13:47:25 +1000


Evan Simpson wrote:
> [options 1 & 2]

No, I didn't like them either ;)


> 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.

How about:

<script tal:define="NAME string:'$dir/dot.jpg'" tal:interpolate>
var img = window.${here/image_name};
img.src = $NAME;
</script>

... so the syntax is the same as the TALES string interpolation. Would
tal:interpolate need an argument? A better name? :)


   Richard's $0.02

-- 
Richard Jones
richard@bizarsoftware.com.au
Senior Software Developer, Bizar Software (www.bizarsoftware.com.au)