[ZPT] Problem calling ZPT on Object(s)
Godefroid Chapelle
gotcha@swing.be
Fri, 22 Mar 2002 15:33:53 +0100
At 19:36 21/03/2002, Christoph Roth wrote:
>Hello,
>
>I'm desperately looking for a hint to solve the following problem:
>
>I have an object "myobj" with a few properties and a Zope Page
>Template "mytemplate" for displaying the object's content. How can I
>call
>the template on the object WHITHOUT putting the template's name into
>the
>URL? I mean saying "http://myhost/myobj" should be enough to have the
>object processed by the template.
>
>I tried something out with an object based upon a DTML-Document
>calling the template via DTML so that the template in turn could read
>the
>object's id out of the request. This worked somehow but seems
>complicated
>to me and not very stable. I feel that there must be an easier way.
>
>Can anybody help? Unfortunately I am still quite a beginner...
1)in your root folder, create a folder 'objects_container'
2)put all your objects in 'objects_container'
3)add 'mytemplate' to the root folder
4)create a python script 'render_object' in the root folder:
object_folder = context.object_container
object = getattr(object_folder, context.id)
return mytemplate(object)
5) for each object in the folder, create a python script with same id
containing
return context.render_object(context)
IOW give access to your users through python scripts (with same ids than
your objects) which return the string rendered by your template.
This is one way to do it among many others. CAUTION, I did not test the above.
>Greetings,
>
>Christoph Roth
>
>_______________________________________________
>ZPT mailing list
>ZPT@zope.org
>http://lists.zope.org/mailman/listinfo/zpt
--
Godefroid Chapelle
BubbleNet sprl
rue Victor Horta, 18 / 202
1348 Louvain-la-Neuve
Belgium
Tel + 32 (10) 459901
Mob + 32 (477) 363942
TVA 467 093 008
RC Niv 49849