RE: RE: DreamWeaver files -> ZPTs: How?

"Ken Winter" <[email protected]>
Newsgroups gmane.comp.web.zope.page-templates
Message-ID <006b01c56000$30c1f050$6b03a8c0@kenxp>
> -----Original Message-----
> From: Chris Beaven [mailto:[email protected]]
> Sent: Monday, May 23, 2005 6:27 PM
> To: [email protected]
> Cc: 'Ian Bicking'; [email protected]
> Subject: Re: [ZPT] RE: DreamWeaver files -> ZPTs: How?
> 
> Ken Winter wrote:
> 
> >The final line:
> >
> >return getattr(context, 'studentlist.htm')
> >
> >evokes a page containing nothing but:
> >
> ><ZopePageTemplate at studentlist.htm>
> >
> >This is at least not an error message!  But I don't know how to get it to
> >render the page instead of just showing this little identifier, or
> whatever
> >it is.
> >
> >Also, I don't know how to pass parameters with this syntax.  The one that
> >comes the closest to working is:
> >
> >return getattr(context, 'studentlist.htm'(data=d))
> >
> >which evokes:
> >
> >Site Error
> >An error was encountered while publishing this resource.
> >Error Type: TypeError
> >Error Value: 'str' object is not callable
> >
> >Which at least implies that this syntax is recognized as an *attempt* to
> >call studentlist.htm!
> >
> >Suggestions?
> >
> >- Ken
> >
> >
> >
> You just need to call the value returned by getattr:
> 
> return getattr(context, 'studentlist.htm')(container, container.REQUEST)
> 
> It's in the Zope Book ;)
> 
> Your attempt at calling was trying to call the string 'studentlist.htm'.
> You can't call a string (it's unlisted in the phone book).

Yessss!  For the record, the final version is:

d = [{'person_id':p.person_id,\
      'first_name':p.first_name,\
      'middle_names':p.middle_names,\
      'last_name':p.last_name}\
     for p in context.read_all_people()]
return getattr(context, 'studentlist.htm')(data=d)

Thanks to Ian and Chris for guiding me through this syntactic maze.

- Ken
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.