[Zope3-dev] Re: wading through zcml...

Martin Aspeli optilude at gmx.net
Wed Dec 6 19:06:24 EST 2006


Chris Withers wrote:
> Jim Fulton wrote:
>> If you want to specify the name of a template in ZCML, then you'll
>> have to invoke some magic.  
> 
> Why can't IView (or whatever it is) just specify that the constructor 
> must accept a request, response and a template instance?

Because the template may not be passed in, and even if it is, where 
would it be constructed and how would it be found again?

If you have this:

class MyView(object):

   def __init__(self, context, request, template):
       self.template = template # IView specifices template = a template
       ...

then you may as well not have a 'template' attribute for <browser:page 
/> at all since you have to do so much work; you could just do this 
(which you can do now, in fact)

class MyView(object):

   template = ViewPageTemplateFile('mytemplate.pt')

   def __init__(self, context, request):
       self.context = context
       self.request = request

If you have it done in ZCML, though, you can get a template-only view 
without any Python at all, though:

<browser:page
     for="*"
     template="mytemplate.pt"
     name="my_view"
     permission="zope.Public"
     />


Martin



More information about the Zope3-dev mailing list