[Grok-dev] Re: RFC: Making the automatic registration of templates more explicit

Martijn Faassen faassen at startifact.com
Wed Jan 31 10:58:39 EST 2007

Philipp von Weitershausen wrote:
> On 30 Jan 2007, at 19:59 , Jan-Wijbrand Kolman wrote:
>> If we need a more explicit way of declaring templates for a module I
>> could imagine allowing the 'grok.template' directive to be used on a
>> module level. You would then get this:
>> qux.py:
>>  import grok
>>  grok.template('fropple')
>>  grok.template('frepple')
>>  ...
>>  grok.template('frupple')

I hadn't considered this one yet. It would be a slightly briefer way to 
make very explicit which templates are in play, as opposed to:

class Fropple:

or alternatively:

class Foo:

> Shrug. I would consider that quite an unnecessary repetition of 
> grok.template(). Heck, you know what I'd end up writing to end the 
> repetition? This:
>   here = os.path.dirname(__file__)
>   for file in os.listdir(os.path.join(here, __name__ + '_templates')):
>       if file.endswith('.pt'):
>           grok.template(file[:-3])
> And then, because I would need it a lot, I'd end up putting this into a 
> reusable function, and voila, we got:
>   grok.autotemplates()

The advance of the method JW proposed would be that you can *see* which 
templates are in play by just looking at the Python code. The drawback 
of the current method, and grok.autotemplates, is that you still don't 
know which templates are really in play unless you go look at a 
directory and compare it with the Python file and think hard which 
templates are there which are not represented by Python.

The nice thing about grok.autotemplates() is that we would turn this 
*off* by default. The alternative JW proposes would be to turn this off 
entirely and only allow explicit template references, with a slightly 
shorter spelling. Does this mean JW that you think the automatic 
association is something you'd never want?



More information about the Grok-dev mailing list