News for hackers. Stuff that matters.
Re:Idea: using code rather than templates to generate HTML by apoirier on Wednesday April 15, 2009 @09:04AM (#563374)
The python Nagare framework use both approaches of programmatic HTML and minimalist HTML templating. For example, to create a HTML list, in a div, from a Python list:

  from nagare.namespaces import xhtml

  l = ['the', 'mandatory', 'hello', 'world']

  h = xhtml.Renderer()
  with h.div(id='content'):
      with h.ul:
          h << [h.li(element) for element in l]

  print h.root.write_htmlstring()
Or a (X)HTML template can have nodes annotated with a 'meld:id=<id>' attribut. They are then retreived and manipulated in Python.

In both cases, one of the main goal is not to reinvent a new syntax / templating language but to use normal Python with all its power. Also the generated (X)HTML is always well-formed.

http://www.nagare.org/trac/wiki/PresentationTier

There are no comments on this comment yet.