[Zope] DTML rendering from python?

Michiel Toneman michiel@ylnd.com
23 Jan 2003 17:37:46 +0100


> >(Un?)Fortunately, I just put the "<p><dtml-var id></p>" in there as an
> >example to simplify the explanation of my problem, and (I think) I have
> >a valid reason for wanting to do this. (I'd love some feedback on this.
> >If you decide I'm nuts anyway, I'll probably have agree with you ;-) )
> 
> Sure.  One of the most frustrating things about these lists is when you put 
> up a trivial example of a complex problem and then you get responses to the 
> example, not the issue itself.
> 

LOL :)

> 
> >My "real" code therefore looks like:
> 
> <snip>
> 
> >         html = "<div>" + HTML(text, level=2, header=0) + "</div>"
> 

 *) sidenote: the <div> is in there to make sure that the XML DOM
    parser doesn't puke because it doesn't have a root/enclosing tag ;-)

> Why not:
> 
> (in Python)
> def get_text(self):
>      return self._htmltxt
> 
> (in DTML)
> <div>
>      <dtml-var "get_text()" fmt="structured-text">
> </div>

Ah I recognise this. That is exactly what I had before I painted myself
into a corner. ;-)

It unfortunately doesn't solve the problem. I want the content manager
to never see the complexity of the rendered HTML, but to work in
structured text. Thus the content manager would write:

----------------------------------------------
First header

  para 1. blablabla
  
  para 2. blablabla

Second header

  para 3. blablabla

----------------------------------------------

This renders to the following HTML (invisible to the content manager)

----------------------------------------------

<h2>First header</h2>
  <p>
    para 1. blablabla
  </p>
  <p>
    para 2. blablabla
  </p>

<h2>Second header</h2>
  <p>
    para 3. blablabla
  </p>

----------------------------------------------

The content manager now adds ((through a click-and-drool interface) a
floating box to paragraph 2 (created by Zope id="box263") and a floating
box to paragraph 3 (id="box544")

Now I'd like my DTML to look like:

----------------------------------------------

<h2>First header</h2>
  <p>
    para 1. blablabla
  </p>
  <p><dtml-var box263>
    para 2. blablabla
  </p>

<h2>Second header</h2>
  <p><dtml-var box554>
    para 3. blablabla
  </p>
----------------------------------------------

The problem is finding the paragraphs, for which I don't think there is
a elegant solution when doing fmt="structured-text" (at least, not
easily). JavaScript + DOM would work, but I don't want to make the site
dependent on client-side JavaScript (that still wouldn't do me any good,
because the DTML wouldn't work client side either). 

Using DOM and python, this is simple, though....

I think the right answer to the question is: "Don't try to put floating
boxes in structured-text content!", which boils down to "Don't do it
that way!" :-) This answer may, however, upset my web-designer to the
point of physical violence :-/ So I'm still looking for a way to render
the resulting DTML the "hard" way. 

If I succeed, I'll write it up in a tutorial, I promise 8-|

Hope you're not too annoyed with me yet ;-)

Greetings,

Michiel