[Zope] cookies

Tapio Hüffner tapio@gmx.net
Fri, 22 Jun 2001 16:38:03 +0200


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