Differences between revisions 1 and 2
Revision 1 as of 2005-06-15 11:22:55
Size: 1134
Editor: ZoomQuiet
Comment:
Revision 2 as of 2009-12-25 07:09:53
Size: 1136
Editor: localhost
Comment: converted to 1.6 markup
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
Here's a quick and dirty module to help when using [http://www.owlfish.com/software/simpleTAL/ SimpleTAL]. Here's a quick and dirty module to help when using [[http://www.owlfish.com/software/simpleTAL/|SimpleTAL]].

Here's a quick and dirty module to help when using SimpleTAL.

Here's an alternative QuixoteAndSimpleTalAdvanced

from simpletal import simpleTAL, simpleTALES
from cStringIO import StringIO
import os.path

# Compiled template cache
_cache = {}

def loadTemplate(filename):
    """
    Load and compile a TAL template file. The compiled template is
    also cached for next time.
    """
    mtime = os.path.getmtime(filename)
    template = _cache.get(filename,None)
    if template and template[1] == mtime:
        return template[0]
    template = simpleTAL.compileHTMLTemplate(file(filename))
    _cache[filename] = (template,mtime)
    return template

def render(filename, d=None):
    """
    Render the template file using information in the d dictionary.
    """
    context = simpleTALES.Context()
    if d:
        for name, value in d.items():
            context.addGlobal(name, value)
    template = loadTemplate(filename)
    out = StringIO()
    template.expand(context,out)
    return out.getvalue()


CategoryCookbook

QuixoteAndSimpleTal (last edited 2009-12-25 07:09:53 by localhost)