[Grok-dev] Trying to wrap my head around GROK

Kevin Teague kevin at bud.ca
Thu Mar 27 22:10:35 EDT 2008


You can customize the rendering of forms by supplying your own page  
template with the template directive. You can copy the default  
template used to render a form from Grok located at 'grok/templates/ 
default_edit_form.pt' into your project, and then begin making the  
desired customizations. You usually want to render your form with a  
shared template that provides header/footer HTML/CSS, etc. I'm doing  
something like this ATM (not sure if it's 100% optimal, but it  
works ...):


file: mygrokapp/layout.py

class ZombieBoss(grok.View):
     grok.context(Interface)


file: mygrokapp/layout_templates/zombieboss.pt

<html metal:define-macro="page">

<head>
   INCLUDE YOUR CSS HERE
</head>

<body>

   <div id="content">
     <div metal:define-slot="content">
         Application information goes here.
     </div>
   </div>

</body>
</html>

file: mygrokapp/myform.py

class ZombieForm(grok.AddForm):
     template = grok.PageTemplateFile('zombieboss_edit_form.pt')
     ALL YOUR REGULAR FORM STUFF GOES HERE

file: mygrokapp/zombieboss_edit_form.pt

<html metal:use-macro="context/@@zombieboss/macros/page">
   <div metal:fill-slot="content">
       ALL THE REGULAR FORM TEMPLATE STUFF GOES HERE
   </div>
</html>

Forms by default are rendered using Widgets, but with a customized  
Form template you don't have to do this. It's "messier" although the  
learning curve is shallower. If you do want to make custom Widgets  
then Web Component Development with Zope 3 has a good section on how  
to do this. Or have a look at megrok.form which is a project to  
provide more/better fields and widgets for working with forms:

http://svn.zope.org/megrok.form/



More information about the Grok-dev mailing list