[Grok-dev] Anyone using Cheetah Template Engine with Grok?
paulalexwilson at gmail.com
Mon Jan 5 18:58:26 EST 2009
2009/1/5 Brian Wolf <brian.wolf at activustech.com>:
> Is anyone using Cheetah Template Engine with Grok?
> I'm having difficulty configuring it to run with Grok. File meta.zcml
> is not found during start-up because, well, it was not created when
> buildout was run. If it must be hand-created, what is the correct
> content and format?
Are you trying to incorporate cheetah as a separate package that plugs
into your project and allows for cheetah templates to be used
automatically like megrok.genshi? Or are you just trying to get
Cheetah working within a project your working on? If it's number 2,
I've had success with an app.py that looks like this:
from Cheetah.Template import Template
class Testcheetah(grok.Application, grok.Container):
pass # see app_templates/index.pt
def setFromString(self, string):
self._template = Template.compile(string)
def setFromFilename(self, filename, _prefix=None):
file = open(os.path.join(_prefix, filename))
self._template = Template.compile(file=file)
def render(self, view):
def __call__(self, filename, _prefix=None):
return CheetahTemplate(filename=filename, _prefix=_prefix)
We need to let our project know that we need Cheetah so our
install_requires in setup.py now looks like:
Also, let buildout know about the change:...
Getting distribution for 'Cheetah'.
Got Cheetah 2.0.1.
Now we need to also create a Cheetah template too called
testcheetahtemplate.ch to match the name of our view and the name we
defined in the cheetah template factory (it could look something like
Hello Cruel $place
$place matches the namespace variable added to the TestCheetahTemplate
If you've called your app 'test' you'll be able to see the templated file at:
Note that you may at one point want to reference the static directory
of your project, you can do this with:
assuming the directory layout of
I have trouble locating this information in the docs...
This is just hacked together quickly with little testing, but should be a start!
Hope that helps.
More information about the Grok-dev