[Grok-dev] Plugging new template language

Santiago Videla santiago.videla at gmail.com
Wed Nov 26 10:56:02 EST 2008


Hi,

I followed the tutorial in
http://grok.zope.org/documentation/how-to/plugging-in-new-template-languagesand
I'm using a combination of Jinja + Yaml + simplejson
to be able to render JSON format from grok.View classes.

Basically I have something like this:

from jinja2 import Template
import yaml, simplejson, grok, os
from grokcore.view.components import GrokTemplate
from grokcore.view.interfaces import ITemplate, ITemplateFileFactory

class JSONTemplate(GrokTemplate):
    grok.implements(ITemplate)

    def setFromString(self, string):
        self._template = Template(string)

    def setFromFilename(self, filename, _prefix=None):
        file = open(os.path.join(_prefix, filename))
        self._template = Template(file.read())

    def render(self, view):
        jinja_render = self._template.render(**self.getNamespace(view))
        yaml_loader = yaml.load(jinja_render)
        return simplejson.dumps(yaml_loader)


I'm doing this because I want to build an application that only use JSON and
some JavaScript framework on the client side (extjs by now). And I didn't
like the way I should use grok.JSON (too much classes and methods).

The question is: is there any way to reload the plugged templates without
restart zope? like grok does with default ZPT

thanks in advance.

-- 
Santiago Videla
www.revolucionesweb.com.ar
http://www.linkedin.com/in/svidela

Sigue la mata dando de que hablar siempre abajo y a la izquierda donde el
pensamiento que se hace corazón resplandece con la palabra sencilla y
humilde que l at s tod at s somos.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.zope.org/pipermail/grok-dev/attachments/20081126/7a83ce6e/attachment.html 


More information about the Grok-dev mailing list