[ZPT] Should tal:content keep surrounding tags?

Evan Simpson evan@digicool.com
Mon, 4 Jun 2001 12:27:06 -0400


From: "Jim Fulton" <jim@digicool.com>
>   A. Define tal:content so that it includes "surrounding" tags.
>      That is, if the marked up tag has one child that is
>      an element, then apply the content-replacement alogorithm
>      recursively to the element as if the tal:content attribute
>      was on the element. In the application of the above rule, maybe
>      apply it if there are three children, which are a text node
>      containing only whitespace characters, an element, and a text node
>      containing only whitespace characters.
>
>   B. Define a new tal attribute/statement with the above semantics.

So, intuitively speaking, you find the innermost tag that is simply nested
in other tags -- no significant siblings, uncles, etc.  If we wrote this as
tal:inner, it might go like this:

Source: <p tal:inner="string:foo"><i><b>A</b></i></p>
Result:  <p><i><b>foo</b></i></p>

Source: <p tal:inner="string:foo"><i><b>A</b>B</i></p>
Result:  <p><i>foo</i></p>

Source: <p tal:inner="string:foo"><i><b>A</b></i><i>B</i></p>
Result:  <p>foo</p>

Alternatively, there are old proposals which nobody ever responded to
(perhaps for lack of experience with the problem) that use more explicit
replacement targets.  These were:

1. A tal:put="target1 expr1;target2 expr2;..." statement that replaces
'target1' with the value of 'expr1' (and so on) in any text inside of the
tag.

Source: <p tal:put="FOO string:foo"><i><b>FOO</b></i></p>
Result:  <p><i><b>foo</b></i></p>

Source: <p tal:put="FOO string:foo"><i><b>FOOing</b></i><i>FOO2</i></p>
Result:  <p><i><b>fooing</b></i><i>foo2</i></p>

2. A tal:interpolate="$" attribute that causes its argument to become an
interpolation marker.  (Richard suggested this without the argument, but for
XML use there has to be *some* argument).  Assuming x='foo':

Source: <p tal:interpolate="$"><i><b>$x</b></i></p>
Result:  <p><i><b>foo</b></i></p>

Source: <p tal:interpolate="$"><i><b>${x}ing</b></i><i>${x}2</i></p>
Result:  <p><i><b>fooing</b></i><i>foo2</i></p>

These two approaches take the attitude that it isn't a bad thing for the
presentation person to be able to see (and perhaps take advantage of) the
fact that certain text is meant to be replaced with dynamic content, as long
as the notation for the targets is simple and flexible.

Cheers,

Evan @ digicool