PyMeld for html templates?

S

Sean Schertell

I'm trying to decide which template system to get married to. I think
I've narrowed it down to PyMeld, Cheetah, or Jinja but leaning
heavily toward PyMeld because I love the idea that your templates are
*totally* clean and that get manipulated from behind the scenes. This
seems to be elegantly inline with the Sacred Creed of separation of
logic from presentation.

Of course I'm going to try them all but I wonder if anyone has any
thoughts on PyMeld as a template system for churning out general
websites?

One important consideration is that even though PyMeld itself doesn't
support template inheritance so far as I know, I'll need to
accomplish that somehow. I want for a URI request to mysite.com/info
to pull in a layout.html template which will in turn be populated by
the info.html template. I've already got the URI mapping stuff
sorted. But how about PyMeld, any ideas on how to do it or whether it
will even work as I've described?

Thanks!

Sean


:::: DataFly.Net ::::
Complete Web Services
http://www.datafly.net
 
B

Bruno Desthuilliers

Sean Schertell a écrit :
I'm trying to decide which template system to get married to. I think
I've narrowed it down to PyMeld, Cheetah, or Jinja but leaning heavily
toward PyMeld because I love the idea that your templates are *totally*
clean and that get manipulated from behind the scenes. This seems to be
elegantly inline with the Sacred Creed of separation of logic from
presentation.

"separating logic from presentation" is often misunderstood. It should
really read "separating application logic from presentation logic", not
"separating presentation logic from html code".
Of course I'm going to try them all

The don't forget to have a look at Genshi and Mako too.

My 2 cents...
 
M

metaperl

Sean Schertell wrote:

Of course I'm going to try them all but I wonder if anyone has any
thoughts on PyMeld as a template system for churning out general
websites?

meld3 evolved from pymeld. I use meld3 -
http://plope.com/software/meld3/
this whole style of templating is known as push-style (coined by
Terence Parr). Most systems are pull-style.

sorted. But how about PyMeld, any ideas on how to do it or whether it
will even work as I've described?

the meat and bread problem: each page has meat and you want to wrap it
with some standard bread. it's a basic tree rewrite and since meld3
uses ElementTree underneath, it is a piece of cake.
 
R

Richie Hindle

[Sean]
I wonder if anyone has any thoughts on PyMeld as a template
system for churning out general websites?

I'm doing that (but then I would be wouldn't I? :cool:
http://www.mandant.net is an example - the content of each page comes
from a file containing just the content, the layout and sidebar are
defined in a template HTML file, and the navigation is built by a
Python script. All that is pulled together using PyMeld into a set of
HTML files and deployed to the web server (there's no need to it on the
fly for that site, but you certainly could).
I want for a URI request to mysite.com/info
to pull in a layout.html template which will in turn be populated by
the info.html template. [...] how about PyMeld, any ideas on how
to do it or whether it will even work as I've described?

You'd do something like this:

from PyMeld import Meld

LAYOUT = """<html><head><title id='title'>The Title</title></head>
<body><div id='info'>The page information goes here.</div>
<p id='footer>Copyright Me 2007.</p></body></html>"""

INFO = """<html><head><title id='title'>The real title</title></head>
<body id='info'><p>Here is the info, which would in the real world
be read from a file.</p></body></html>"""

page = Meld(LAYOUT)
info = Meld(INFO)
page.title = info.title._content
page.info = info.info._content
print page

Is that the sort of thing you had in mind?
 
S

Sean Schertell

I'm trying to get PyMeld happening but I'm a bit stumped as to how to
make it work with mod_python.

The pymeld docs show examples only for the Python command line
interpreter and show using the print statement to output stuff. But
using mod_python.apache, I think you need to use req.write(something)
format. And of course, this fails when you feed it output from Meld.

Any tips?

Sean



[Sean]
I wonder if anyone has any thoughts on PyMeld as a template
system for churning out general websites?

I'm doing that (but then I would be wouldn't I? :cool:
http://www.mandant.net is an example - the content of each page comes
from a file containing just the content, the layout and sidebar are
defined in a template HTML file, and the navigation is built by a
Python script. All that is pulled together using PyMeld into a set of
HTML files and deployed to the web server (there's no need to it on
the
fly for that site, but you certainly could).
I want for a URI request to mysite.com/info
to pull in a layout.html template which will in turn be populated by
the info.html template. [...] how about PyMeld, any ideas on how
to do it or whether it will even work as I've described?

You'd do something like this:

from PyMeld import Meld

LAYOUT = """<html><head><title id='title'>The Title</title></head>
<body><div id='info'>The page information goes here.</div>
<p id='footer>Copyright Me 2007.</p></body></html>"""

INFO = """<html><head><title id='title'>The real title</title></head>
<body id='info'><p>Here is the info, which would in the real world
be read from a file.</p></body></html>"""

page = Meld(LAYOUT)
info = Meld(INFO)
page.title = info.title._content
page.info = info.info._content
print page

Is that the sort of thing you had in mind?
 
R

Richie Hindle

[Sean]
The pymeld docs show examples only for the Python command line
interpreter and show using the print statement to output stuff. But
using mod_python.apache, I think you need to use req.write(something)
format. And of course, this fails when you feed it output from Meld.

req.write(str(meld)) ?
 

Members online

Forum statistics

Threads
473,815
Messages
2,569,705
Members
45,494
Latest member
KandyFrank

Latest Threads

Top