From 29b888c68c7d4c6a18627f09bcd5db865bcbcaef Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Sat, 16 Aug 2008 09:10:09 +0000 Subject: Add "get_template" to template module. --- repoze/bfg/template.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'repoze/bfg/template.py') diff --git a/repoze/bfg/template.py b/repoze/bfg/template.py index 0d390fecf..3c60dd19e 100644 --- a/repoze/bfg/template.py +++ b/repoze/bfg/template.py @@ -67,13 +67,8 @@ def registerTemplate(type, template, path): else: sm.registerUtility(template, type, name=path) -def render_template(path, **kw): - """ Render a z3c.pt (ZPT) template at the package-relative path - (may also be absolute) using the kwargs in ``*kw`` as top-level - names and return a string. """ +def _get_template(path, **kw): # XXX use pkg_resources - path = caller_path(path) - template = queryUtility(ITemplate, path) if template is None: @@ -82,6 +77,20 @@ def render_template(path, **kw): template = Z3CPTTemplateFactory(path) registerTemplate(ITemplate, template, path) + return template + +def get_template(path): + """ Return a z3c.pt template object at the package-relative path + (may also be absolute) """ + path = caller_path(path) + return _get_template(path).template + +def render_template(path, **kw): + """ Render a z3c.pt (ZPT) template at the package-relative path + (may also be absolute) using the kwargs in ``*kw`` as top-level + names and return a string. """ + path = caller_path(path) + template = get_template(path) return template(**kw) def render_template_to_response(path, **kw): -- cgit v1.2.3