Hello all, I'm starting to learn ZPT in Zope and I have a question. Can I make ZPT includes in my templates, like I can include dtml . I want to use some template code in all the rest of the templates in my application, is there a way to include this or I need to copy the code in every document? Also like in php when you include a php document to use it in several php documents. thanks in advance Gerardo Amaya
Look in the Zope Book : http://www.zope.org/Members/michel/ZB The chapter on Advanced Page Templates, as well as the Page Templates Reference will tell you how. Of course you might want to read the chapter on Page Templates first. But, basically, you define a macro in your source template by using something like: <span metal:define-macro="usefulbit">This is a <b>useful</b> snippet that I can re-use elesewhere</span> Then in your destination template, you write: <span metal:use-macro="here/source_template.html/macros/usefulbit"> default content </span> Felix. On Fri, Jul 26, 2002 at 09:01:20AM -0600, Jose Gerardo Amaya Giron wrote:
Hello all, I'm starting to learn ZPT in Zope and I have a question.
Can I make ZPT includes in my templates, like I can include dtml . I want to use some template code in all the rest of the templates in my application, is there a way to include this or I need to copy the code in every document?
On Fri, 2002-07-26 at 09:21, Felix Ulrich-Oltean wrote:
Look in the Zope Book : http://www.zope.org/Members/michel/ZB
The chapter on Advanced Page Templates, as well as the Page Templates Reference will tell you how. Of course you might want to read the chapter on Page Templates first.
But, basically, you define a macro in your source template by using something like:
<span metal:define-macro="usefulbit">This is a <b>useful</b> snippet that I can re-use elesewhere</span>
Then in your destination template, you write:
<span metal:use-macro="here/source_template.html/macros/usefulbit"> default content </span>
Felix.
First of all thanks Felix for your reply. I ckeck the zope book and your example, but I still have one more question. When I define a macro I can add any ZPT code I want, I mean I can add code that calls SQL Methods, scripts etc or is just for dtml code purposes. I mean just to reuse dtml for looks or I can jsut for everything. Imagine I want to implement some user control or get some user preferences from a database for each template I have, can I include it in a macro and use it later on. thanks in advance Gerardo Amaya
Gerardo, The answer is YES. The macros you import can do some processing first - I've done this before, e.g. definig a macro that makes a dynamic menu based on folder structure and then using it in another template. The best way to find out is probably to try it out. Felix. On Fri, Jul 26, 2002 at 09:46:11AM -0600, Jose Gerardo Amaya Giron wrote:
First of all thanks Felix for your reply. I ckeck the zope book and your example, but I still have one more question. When I define a macro I can add any ZPT code I want, I mean I can add code that calls SQL Methods, scripts etc or is just for dtml code purposes. I mean just to reuse dtml for looks or I can jsut for everything. Imagine I want to implement some user control or get some user preferences from a database for each template I have, can I include it in a macro and use it later on.
participants (2)
-
Felix Ulrich-Oltean -
Jose Gerardo Amaya Giron