davidf at sjsoft.com
Fri Oct 31 10:42:52 EST 2003
Greg Stein wrote:
>On Thu, Oct 30, 2003 at 10:44:52AM -0600, Ian Bicking wrote:
>>On Thursday, October 30, 2003, at 10:33 AM, Gregory (Grisha) Trubetskoy
>>>HTMLgen has a DocumentTemplate thing which is a bare bones templating
>>>system allowing for substitution in a text file. I think something
>>>primitive of this sort and perhaps implemented based on this:
>>>(which can probably be even further optimized)
>>>would be nice to have in stdlib.
>>A templating system in its most naive form is just a kind of string
>>substitution. If that's the kind of thing we're looking for, then
>>perhaps -- but it has to be usefully better than %. (Though % would be
>Right. Simple interpolation is rarely enough. The features that I found to
>be useful in a templating system:
>* structured objects (i.e. something like: foo.bar)
>* including sub-templates
>I've also found that *restricting* the functionality to just this limited
>set helps to provide clarity and avoid complex abuses of templates. I look
>at the task simply as "rendering data" and prefer a simple syntax and
>functionality to match that.
>p.s. yah yah, this is an implicit pimping of my ezt module :-)
What I've found really helpful in my jtoolkit framework is to allow
anything to go inside a tag object (in between the start and end tags),
including a string, another tag object, or a list of any of the above.
The toolkit then expands any of the required items.
pagelinks = 
for pagelinknum in range(1, len(pages)+1):
pagelinktext = "Page %d" % pagelinknum
if pagelinknum = currentpagenum:
pagelinktext += " (current)"
pagelinklink = '?page=%d' % pagelinknum
e.g. widgets.Page(title, contents=[widgets.Paragraph(pagelinks),
More information about the Web-SIG