Jose,

thanks for your thoughts.

On Wednesday 04 April 2007 18:01, Jose Galvez wrote:
> Ok I see what your doing, what I would do is break out the code that
> gets the entry from the database into a separate function and then use
> that to populate what ever you need.

Getting the information from the database is one part of the redundancy. 
That solves the controller part. Although a mode.get_by(id) is not much to 
do. So it's probably not worth avoiding the one-line-redundancy here. I'm 
more worried about the template.

> Alternativly if you want to reduce the redundancy because essentially
> same.mako is the "content" fragment you could just use the mako include
> tag to have index.mako include save.mako so now your index.mako would
> look like:
> <h1> Curriculum vitae</h1>
> <%include file="save.mako" />

It looks like the <%include/> tag is indeed the right solution. I made a 
few experiments with <%def/> but it has the disadvantage that I cannot 
load the template containing te <%def/>s like 
render_response('my-defs.mako') and call the def inside that template at 
the same time. So <%def/>s seem to be only useful when being called from a 
template but not from a controller.

Regarding <%include/>s: the issue I had with <%include/> tags was that I 
couldn't pass through variables. I tried:

show.mako:

<h1> Curriculum vitae</h1>
for entry in c.entries:
<%include file="display-entry.mako" />

display-entry.mako

My name is ${ entry.name }.

I just got errors that "entry" is undefined in the display-entry.mako. So I 
first thought that passing my variables through wouldn't work at all. 
Fortunately I got the hint on IRC that I can use the 'c' variable to pass 
on variables. So this works better:

show.mako:

<h1> Curriculum vitae</h1>
for c.entry in c.entries:
<%include file="display-entry.mako" />

display-entry.mako

My name is ${ c.entry.name }.

I don't really understand the way that Mako scopes variables. :( But at 
least this is a solution because I can also call 
render_response('display-entry.mako') from the controller to show the 
entry.

 Christoph

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to