Composing variables
Good day everyone I've defined some archetypes that contain fields like Title_en, Title_de, Content_en, Content_de, etc. Assuming that I've set a language var related to URL like (lang = 'en'), how can i access them? Thanks, Cristi
--On 28. Juli 2005 11:59:09 +0300 Cristi Barladeanu <kristache@gmail.com> wrote:
Good day everyone
I've defined some archetypes that contain fields like Title_en, Title_de, Content_en, Content_de, etc. Assuming that I've set a language var related to URL like (lang = 'en'), how can i access them?
Please ask AT related questions on the at-users list. In general you should not access attributes in AT directly but only through the accessor methods. There is something like getField(fieldname) in the AT which might help you (look also at the AT docs). -aj
Hello Andreas and thank for your answer. I've posted this question to at-users list too but still no answer. In fact this problem is not related only to AT. Let me give you an example: var alternative = 'bar' or 'baz' var foo_baz = 'content based on baz' var foo_bar = 'content based on bar' These can be defined either in ZPT, DTML or Python Script. The problem is the same. The question is how can I obtain the value of foo_$alternative. An example written in PHP: $alternative = "bar"; $foo_bar = "content based on bar"; echo ${"foo_".$alternative} This will produce "content based on bar". Thanks for your time, Cristi On 7/28/05, Andreas Jung <lists@andreas-jung.com> wrote:
--On 28. Juli 2005 11:59:09 +0300 Cristi Barladeanu <kristache@gmail.com> wrote:
Good day everyone
I've defined some archetypes that contain fields like Title_en, Title_de, Content_en, Content_de, etc. Assuming that I've set a language var related to URL like (lang = 'en'), how can i access them?
Please ask AT related questions on the at-users list. In general you should not access attributes in AT directly but only through the accessor methods. There is something like getField(fieldname) in the AT which might help you (look also at the AT docs).
-aj
Am 29.07.2005, 18:02 Uhr schryb Cristi Barladeanu <kristache@gmail.com>:
An example written in PHP:
$alternative = "bar"; $foo_bar = "content based on bar"; echo ${"foo_".$alternative}
same in a Python-Skript: ------------------------------------------------------------------ foo = {"bar": "content based on bar", "baz": "content based on baz", } alternative = "bar" print foo[alternative] ------------------------------------------------------------------ or, if foo_bar and foo_baz are attributes in your current context: ------------------------------------------------------------------ alternative = "bar" print getattr(context, "foo_%s"%alternative) ------------------------------------------------------------------ HTH Jo. -- internetmanufaktur jo----------------------------- Berlin, Germany |||||||||||||||meder-------------------fon: ++49-30-417 17 63 33 http://www.meder.de/ ------------------- fax: ++49-30-417 17 63 45 Kollwitzstr. 75 ------------------------ mob: ++49-170- 2 98 89 97 10435 Berlin ---------------http://www.meder.de/keys/jo-pubkey.txt
I don't know if this is what you are looking for, but can use a form of indirection that is available thru dtml: <dtml-call "REQUEST.set('a1', 'aaa')"> <dtml-call "REQUEST.set('b1', 'a1')"> <dtml-var b1> <br> <dtml-var "_[b1]"> will print: a1 aaa This will allow you to load variable b1 within a 'pointer' to a variable containing the data you want. hth Jonathan ----- Original Message ----- From: Cristi Barladeanu To: Andreas Jung Cc: zope@zope.org Sent: Friday, July 29, 2005 12:02 PM Subject: Re: [Zope] Composing variables Hello Andreas and thank for your answer. I've posted this question to at-users list too but still no answer. In fact this problem is not related only to AT. Let me give you an example: var alternative = 'bar' or 'baz' var foo_baz = 'content based on baz' var foo_bar = 'content based on bar' These can be defined either in ZPT, DTML or Python Script. The problem is the same. The question is how can I obtain the value of foo_$alternative. An example written in PHP: $alternative = "bar"; $foo_bar = "content based on bar"; echo ${"foo_".$alternative} This will produce "content based on bar". Thanks for your time, Cristi On 7/28/05, Andreas Jung <lists@andreas-jung.com> wrote: --On 28. Juli 2005 11:59:09 +0300 Cristi Barladeanu <kristache@gmail.com> wrote: > Good day everyone > > I've defined some archetypes that contain fields like Title_en, Title_de, > Content_en, Content_de, etc. > Assuming that I've set a language var related to URL like (lang = 'en'), > how can i access them? > Please ask AT related questions on the at-users list. In general you should not access attributes in AT directly but only through the accessor methods. There is something like getField(fieldname) in the AT which might help you (look also at the AT docs). -aj ------------------------------------------------------------------------------ _______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Thank you all very much for your answers. The second solution that Jo provided worked exactly as I wanted: .. tal:content="python: getattr(obj, 'Title_%s'%lang)".. A good day to you all, Cristi On 7/29/05, Jonathan <dev101@magma.ca> wrote:
I don't know if this is what you are looking for, but can use a form of indirection that is available thru dtml: <dtml-call "REQUEST.set('a1', 'aaa')"> <dtml-call "REQUEST.set('b1', 'a1')"> <dtml-var b1> <br> <dtml-var "_[b1]"> will print: a1 aaa This will allow you to load variable b1 within a 'pointer' to a variable containing the data you want. hth Jonathan
----- Original Message ----- *From:* Cristi Barladeanu <kristache@gmail.com> *To:* Andreas Jung <lists@andreas-jung.com> *Cc:* zope@zope.org *Sent:* Friday, July 29, 2005 12:02 PM *Subject:* Re: [Zope] Composing variables
Hello Andreas and thank for your answer. I've posted this question to at-users list too but still no answer. In fact this problem is not related only to AT. Let me give you an example:
var alternative = 'bar' or 'baz' var foo_baz = 'content based on baz' var foo_bar = 'content based on bar'
These can be defined either in ZPT, DTML or Python Script. The problem is the same. The question is how can I obtain the value of foo_$alternative.
An example written in PHP:
$alternative = "bar"; $foo_bar = "content based on bar"; echo ${"foo_".$alternative}
This will produce "content based on bar".
Thanks for your time, Cristi
On 7/28/05, Andreas Jung <lists@andreas-jung.com> wrote:
--On 28. Juli 2005 11:59:09 +0300 Cristi Barladeanu <kristache@gmail.com
wrote:
Good day everyone
I've defined some archetypes that contain fields like Title_en, Title_de, Content_en, Content_de, etc. Assuming that I've set a language var related to URL like (lang = 'en'), how can i access them?
Please ask AT related questions on the at-users list. In general you should not access attributes in AT directly but only through the accessor methods. There is something like getField(fieldname) in the AT which might help you (look also at the AT docs).
-aj
------------------------------
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
participants (4)
-
Andreas Jung -
Cristi Barladeanu -
Jo Meder -
Jonathan