[Grok-dev] Template directories

Brandon Craig Rhodes brandon at rhodesmill.org
Wed Jun 25 07:43:45 EDT 2008

Tim Terlegård <tim.terlegard at valentinewebsystems.se> writes:

> I wonder what people think about the current directory layout for
> templates.  What about adding a global template directory? ...

I'm afraid I would dislike this, because it would mean there was more
than one place, when reading someone else's code, to go looking for
their template.  I was struck, when reading a blog entry the other day,
by the statement that when someone went and looked at someone else's
Rails app, he knew immediately right where to look for everything -
where views would be, where models would be, and so forth.

Which, incidentally, we do not have in Grok today; from one Grok app to
another, there's no way to predict which files define the Models, which
files define Views (sometimes with the corresponding Models, sometimes
separate), where the Indexes have been declared (you have to therefore
search the entire code base to see for which Models there are indexes),
and where all of the Traversers are that make URLs work if the ZODB is
not beneath a particular container or objects (each Traverser might be
in the same place as the object it wraps, avoiding grok.context() calls,
or they might be all in one file so that you can "read down" through
that file and "see" how they string together to permit multi-part URLs;
but this puts them far from the containers or models they're atop - we
still need to explain that spaghetti-code thing to Martijn sometime).

Anyway, if you want several views in several places to share a template,
then I think it's preferable to do something like:


   class Master(grok.View):
       grok.baseclass()  # template is in templates/master.pt

   from myapp import templates

   class ViewFoo(templates.Master):

   from myapp import templates

   class ViewBar(templates.Master):

(Or am I entirely wrong?  Is grok.template() inherited?)

What I like about using the existing rules like this is not only the
simplicity, but the utter explicitness: you know exactly where to go in
each case to find something, and never have to look two places.  Thanks
to the "import" statements and to the fact that the Master template can
only be one place, everything points back to the resources it uses
without any ambiguity about where they can be found.

Brandon Craig Rhodes   brandon at rhodesmill.org   http://rhodesmill.org/brandon

More information about the Grok-dev mailing list