[Grok-dev] Viewlets
Maurits van Rees
m.van.rees at zestsoftware.nl
Thu Jul 15 05:43:48 EDT 2010
Op 14-07-10 16:32, Daniel Lyons schreef:
> Hi again,
>
> I'm still working through _Grok 1.0 Web Development_ but also trying
> to apply the lessons in a small app that does the same thing as the
> todo list app, but structured somewhat differently. In the book,
> pretty much everything winds up in the app.py file, which seems fine
> for a tutorial, but as I rewrite it I have been trying to break things
> down into app.py, todolist.py and todo.py but I've run into a
> connundrum with handling viewlets. So I now think I may have
> completely lost how viewlets work in my mind.
Some day I want to move my personal website from Plone to Grok using the
techniques in the Grok 1.0 Web Development book from Carlos de la
Guardia. Ask me again in a year. ;-)
> In general, how does one use viewlets to structure an application? I
> have the master template in app_templates/master.pt but it seems as
> though to use this template the view must be in app.py rather than
> (say) todolist.py. Also, I'm wondering why it's strictly necessary to
> have both a view and viewlet class. Seems like it's going to lead to
> twice as many classes, one for each "page" I want to have and one to
> embed that page in a viewlet. Is that right? Am I misunderstanding
> something?
You indeed need two classes for each page. The viewlet contains only
the actual content, and the page adds stuff like navigation, a login
link, header, footer, picture of your dog/dinosaur, etcetera, ensuring a
consistent look throughout the site.
Having the main content of an object available as a viewlet, makes it
easier to insert that into a different page (for example a page showing
the last three of these objects) or to refresh only the content part of
a page using some javascript. I think I like it.
Cheers,
--
Maurits van Rees
Programmer, Zest Software
More information about the Grok-dev
mailing list