ZPT - using templates based on variables
Hi all, Assume I have a ZPT documant that looks like this: <html xmlns:tal="http://xml.zope.org/namespaces/tal" xmlns:metal="http://xml.zope.org/namespaces/metal" metal:use-macro="here/StandardLookAndFeel/macros/master"> <head> <title tal:content="here/title">The title</title> </head> <body bgcolor="#ffffff"> <div metal:fill-slot="main"> <h1>UserList</h1> </div> <span tal:define="def_dn string:o=cm;dn request/dn | def_dn" metal:fill-slot="userList_slot" tal:content="structure python:here.userList(dn=dn)"> User List goes here </span> <p tal:content="structure here/ZopeAttributionButton"></p> </body> </html> This works fine and dandy, but can anyone think of a way in which I could replace the metal:use-macro="here/StandardLookAndFeel/macros/master"> line with something like metal:use-macro="here/StandardLookAndFeel/macros/$master_template"> , where master_template is a variable, maybe a session variable or similar. This would open up the possibilities no end, imagine skins using ZPT. Anyone have any ideas? Phil
hello ng, I've a problem with setting and using cookies. My Website is completely folder-structured. My Menue lists the foldernames and each folder inherits the index_html from the root folder. The foldernames are properties (english or german) Now I want to switch between two languages. The idea is that the user clicks on "german" and a cookie is set with the name 'lang' and its value 'german'. Then the page is reloaded with the german folder-names and different content. If the user clicks on english again, the cookie should be overwritten with the value 'english'. The cookie is only set or changed by clicking on the switch-button. The webpage should work like that: <dtml-if expr="lang=='english'"> ...english content and english menue <dtml-elif expr="lang=='deutsch'"> ...german content and german menue </dtml-if> I've tried to realise the switching in this way. the code in the index_html: ("switch-button") <dtml-if expr="lang=='english'"> <a href="&dtml-absolute_url;/sprache_de">Deutsch <dtml-elif expr="lang=='deutsch'"> <a href="&dtml-absolute_url;/sprache_en">English </dtml-if> Two Methods in the rootfolder set the cookie. ("switch-methods") Sprache_de: switching from english to german <dtml-call "RESPONSE.setCookie('lang', 'deutsch')" > <dtml-call expr="RESPONSE.redirect(URL1)"> Sprache_en: switching from german to english <dtml-call "RESPONSE.setCookie('lang', 'english')" > <dtml-call expr="RESPONSE.redirect(URL1)"> I had always a look at the REQUEST and I saw that this doesn't work very well. Sometimes the cookie isn't set. Or I can see the changes, if I click on another folder. Another problem is that some folders are english and some are german at the same time. But I wanted to use the cookie as a global variable in order to have either a english or a german version provided to the user. Does every folder creates its own cookie. I want to be able to switch the language also in subfolders. I hope you got my problem. It isn't easy to explain as short es possible. Thanks, Tapio
maybe this could be a hint to the solution of your problem: if you have problems with the "visibility" of your cookies use: setCookie(..., path='/', ...) in general cookies are set via the "set-cookie"-tag in the http-header. So you allways have to be sure, that a page (maybe dummy-page with redirect) with a "set-cookie"-header is delivered to the client-browser bevore referencing to the cookie in the context of another page. maybe the API-method "expireCookie" can also be used fruitfully. Andreas -------------------
hello ng,
I've a problem with setting and using cookies.
My Website is completely folder-structured. My Menue lists the foldernames and each folder inherits the index_html from the root folder. The foldernames are properties (english or german)
Now I want to switch between two languages. The idea is that the user clicks on "german" and a cookie is set with the name 'lang' and its value 'german'. Then the page is reloaded with the german folder-names and different content. If the user clicks on english again, the cookie should be overwritten with the value 'english'. The cookie is only set or changed by clicking on the switch-button. The webpage should work like that:
<dtml-if expr="lang=='english'"> ...english content and english menue <dtml-elif expr="lang=='deutsch'"> ...german content and german menue </dtml-if>
I've tried to realise the switching in this way.
the code in the index_html: ("switch-button")
<dtml-if expr="lang=='english'"> <a href="&dtml-absolute_url;/sprache_de">Deutsch <dtml-elif expr="lang=='deutsch'"> <a href="&dtml-absolute_url;/sprache_en">English </dtml-if>
Two Methods in the rootfolder set the cookie. ("switch-methods")
Sprache_de: switching from english to german
<dtml-call "RESPONSE.setCookie('lang', 'deutsch')" > <dtml-call expr="RESPONSE.redirect(URL1)">
Sprache_en: switching from german to english
<dtml-call "RESPONSE.setCookie('lang', 'english')" > <dtml-call expr="RESPONSE.redirect(URL1)">
I had always a look at the REQUEST and I saw that this doesn't work very well. Sometimes the cookie isn't set. Or I can see the changes, if I click on another folder. Another problem is that some folders are english and some are german at the same time. But I wanted to use the cookie as a global variable in order to have either a english or a german version provided to the user. Does every folder creates its own cookie. I want to be able to switch the language also in subfolders.
I hope you got my problem. It isn't easy to explain as short es possible.
Thanks,
Tapio
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
=?iso-8859-1?Q?Tapio=5FH=FCffner?= writes:
I've a problem with setting and using cookies. I expect, you need to set the cookie path.
See URL:http://www.dieter.handshake.de/pyprojects/zope/book/chap3.html for details. Dieter
Just a note to say this is possible and works remarkably well: By changing this line to metal:use-macro="here/StandardLookAndFeel/macros/master"> line with something like metal:use-macro="python:path('here/%s/macros/master' % path('here/lookandfeel'))"> Where 'lookandfeel' is a property of the containing folder. This means that I can use ZPT to 'skin' my site, yay, happy me! Phil phil.harris@zope.co.uk ----- Original Message ----- From: "Phil Harris" <phil.harris@zope.co.uk> To: <zope@zope.org> Sent: Friday, June 22, 2001 2:40 PM Subject: [Zope] ZPT - using templates based on variables
Hi all,
Assume I have a ZPT documant that looks like this:
<html xmlns:tal="http://xml.zope.org/namespaces/tal" xmlns:metal="http://xml.zope.org/namespaces/metal" metal:use-macro="here/StandardLookAndFeel/macros/master"> <head> <title tal:content="here/title">The title</title> </head> <body bgcolor="#ffffff"> <div metal:fill-slot="main"> <h1>UserList</h1> </div> <span tal:define="def_dn string:o=cm;dn request/dn | def_dn" metal:fill-slot="userList_slot" tal:content="structure python:here.userList(dn=dn)"> User List goes here </span> <p tal:content="structure here/ZopeAttributionButton"></p> </body> </html>
This works fine and dandy, but can anyone think of a way in which I could replace the
metal:use-macro="here/StandardLookAndFeel/macros/master">
line with something like
metal:use-macro="here/StandardLookAndFeel/macros/$master_template">
, where master_template is a variable, maybe a session variable or similar.
This would open up the possibilities no end, imagine skins using ZPT.
Anyone have any ideas?
Phil
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
participants (4)
-
Andreas Hölzl -
Dieter Maurer -
Phil Harris -
Tapio Hüffner