[ZPT] Should tal:content keep surrounding tags?

Jim Fulton jim@digicool.com
Fri, 01 Jun 2001 19:35:08 -0400


Brad Clements wrote:
> 
> On 1 Jun 2001, at 13:29, Jim Fulton wrote:
> 
> > > >   A. Define tal:content so that it includes "surrounding" tags.
> > >
> > > For some reason I don't like this idea, but I don't know why. Maybe there's an
> > > interaction with macros?
> >
> > My first reaction was negative, but it has grown on me. Part of the justification
> > is that I don't think of tags as content, so saying that in:
> >
> >   <td><font color="white"><font size="+1"><i>splat</i></font></font></td>
> >
> > the content to be replaces is "splat" feels easonable.
> 
> So you're saying that tal:content will recurse childNodes until it reaches the end,
> replace the text of that node, then output all of the recursed nodes?
> 
> What about this?
> 
>    <td ta:content="here/splat">
>         <font color="white"><font size="+1"><i>splat</i><br />more text
>         </font></font>
>     </td>
> 
> I'm not so much concerned with "more text", but the <br /> which could be <hr />

You snipped my orginal proposal, which was a bit precise about how recursion
would be done. :)

In the above example, it would replace the content of the innermost font element:

   <td ta:content="here/splat">
        <font color="white"><font size="+1">replacement</font></font>
    </td>

> I've posted two messages in the past 2 weeks about this.

Sorry. :)

> On may 27th,
> 
> > I need to apply a single condition test to a static element and a loop.
> >
> > Here's what I have:
> >
> > <span tal:define="wt here/WoodTypes"
> >    tal:condition="python:'soft' in wt">
> > <h3>Soft Wood Types</h3>
> > <span tal:repeat="typ here/SoftWoodTypes"
> >       tal:replace="structure string:$typ<br />">ficklmire</span>
> > </span>
> >
> >
> > Two uglies with this
> >
> > 1. The outer span remains in the html. What I'd like is something like
> >
> >  tal:replace="structure contents"
> >
> > In the outer span so that it's not included in the output. "contents" means the children of
> > this html element.

Hm. Interesting.

> > 2. see the ugly use of
> >
> > tal:replace="structure string:$typ<br />"
> >
> > I wish there was a better way to do this, though I'm not sure what. I had previously used
> > a span as the repeat, but again I couldn't eliminate the outer span .. it was ugly.
> >
> > If I had a tal:replace="structure contents"  then that would fix this.
> >
> > Perhaps I'm missing something?

I dunno.
 
> And
> 
> > I'm still looking for a way to have a tal:repeat that does NOT include the enclosing
> > element.
> >
> > Like
> >
> > <span tal:repeat="item in items">
> >     <h1 tal:content="repeat/item/title">The title</h1>
> >     <p tal:content="repeat/item/description">The description</p><br />
> > </span>
> >
> > The idea is that I don't want the outer <span> to be in the output, just
> >
> > <h1>The title</h1>
> > <p>Descrption</p><br />
> >
> > (bad example but you get the idea)

This sounds like the same thing you had above.  It's similar to
the difference between replace and contents.  

Sorta smells like there's a generalization lurking here. :)
Obviously, one could add a tal directive that indicated that
the element containing the tal directive should be ommitted
from the output.

For HTML, I think it would be reasonable to 
remove any span tags that contained *only* tal attributes.
(There should be an option to retain tal markup in output, 
and, in this case, the spans would not be removed.)
Of course, this doesn't generalize to non-HTML XML....

With either of the above, we could *almost* be rid of replace, 
except for the `replace="nothing"' case. Of course, we could
bring back dummy. :)  

Jim

--
Jim Fulton           mailto:jim@digicool.com   Python Powered!        
Technical Director   (888) 344-4332            http://www.python.org  
Digital Creations    http://www.digicool.com   http://www.zope.org