Feeling like a newbie.. document id if statement?
Ok.. this is really dumb, but for some reason I can't get this to work. <dtml-if "id=='index_html'"> do something cool </dtml-if> What am I missing? I tried it on a few pages.. nothing.. Thanks, J (duffus)
J, You may not be as dumb as you think. If I recall correctly, id is one of those strange fish which is sometimes string and sometimes method. So if in your case it is a method then id=='anything' will always be false. Try id()=='index_html'. hth Phil phil.harris@zope.co.uk ----- Original Message ----- From: "J. Atwood" <jatwood@bwanazulia.com> To: <zope@zope.org> Sent: Wednesday, May 24, 2000 12:59 PM Subject: [Zope] Feeling like a newbie.. document id if statement?
Ok.. this is really dumb, but for some reason I can't get this to work.
<dtml-if "id=='index_html'">
do something cool
</dtml-if>
What am I missing? I tried it on a few pages.. nothing..
Thanks, J (duffus)
_______________________________________________ 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 )
"J. Atwood" wrote:
Ok.. this is really dumb, but for some reason I can't get this to work.
<dtml-if "id=='index_html'">
I believe this should be <dtml-if "_['id']=='index_html'"> (isn't dtml nice sometimes) Rik
Thank you Phil and Rick, that did the trick (sorry) and I am back to feeling like a Zopista! J At 2:19 PM +0200 5/24/2000, Rik Hoekstra wrote:
"J. Atwood" wrote:
Ok.. this is really dumb, but for some reason I can't get this to work.
<dtml-if "id=='index_html'">
I believe this should be
<dtml-if "_['id']=='index_html'">
(isn't dtml nice sometimes)
Rik
On Wed, 24 May 2000, Rik Hoekstra wrote:
"J. Atwood" wrote:
Ok.. this is really dumb, but for some reason I can't get this to work.
<dtml-if "id=='index_html'">
I believe this should be
<dtml-if "_['id']=='index_html'">
I wonder if someone would be kind enough to translate Rik's code into Enlish for me. I know that expressions inside "" are Python, but what is the function of the [] and _? -Tim -- Tim Wilson | Visit Sibley online: | Check out: Henry Sibley HS | http://www.isd197.k12.mn.us/ | http://www.zope.org/ W. St. Paul, MN | | http://slashdot.org/ wilson@visi.com | <dtml-var pithy_quote> | http://linux.com/
_ is the default namespace which you can treat sort of like a dictionary, so this means you can index into it with the name 'things'. so _['id'] means give me the id of the current namespace. well sort of. ----- Original Message ----- From: "Timothy Wilson" <wilson@visi.com> To: "Rik Hoekstra" <rik.hoekstra@inghist.nl> Cc: "J. Atwood" <jatwood@bwanazulia.com>; <zope@zope.org> Sent: Wednesday, May 24, 2000 3:18 PM Subject: Re: [Zope] Feeling like a newbie.. document id if statement?
On Wed, 24 May 2000, Rik Hoekstra wrote:
"J. Atwood" wrote:
Ok.. this is really dumb, but for some reason I can't get this to
work.
<dtml-if "id=='index_html'">
I believe this should be
<dtml-if "_['id']=='index_html'">
I wonder if someone would be kind enough to translate Rik's code into Enlish for me. I know that expressions inside "" are Python, but what is the function of the [] and _?
-Tim
-- Tim Wilson | Visit Sibley online: | Check out: Henry Sibley HS | http://www.isd197.k12.mn.us/ | http://www.zope.org/ W. St. Paul, MN | | http://slashdot.org/ wilson@visi.com | <dtml-var pithy_quote> | http://linux.com/
_______________________________________________ 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 )
<dtml-if "_['id']=='index_html'">
I wonder if someone would be kind enough to translate Rik's code into Enlish for me. I know that expressions inside "" are Python, but what is the function of the [] and _?
Hm, I'm afraid this is a DTML trick (nothing more). I hope I can explain this right. Please correct me if I go wrong. Normally in DTML, you access variables in the current namespace with <dtml-var id>, which actually stands for <dtml-var name="id"> In an expression like the one used by J you actually use an expression, like <dtml-var expr="id">, in which case you do not get the id variable in the current namespace, but the actual value of the id attribute (property) of the object in the current namespace. The problem here is that the id of index_html is a python method (which is actually returned by <dtml-var expr="id">). This will never be equal to 'index_html' as that is a string. The solution is to call the variable in the current object namespace by using it like a dictionary in the python expression <dtml-var expr="_['id']">. Because it's a method, you could (in this case) also use <dtml-var expr="id()">, in which case a string is returned (so that <dtml-if expr="id()=='index_html'"> will once again be useful. However, the _['id'] is preferred, because it will work on different objects and the id of most other objects is a string. For example: <dtml-in "objectValues(['DTML Method', 'File'])"> <dtml-if "_['id'] == 'somestring'"> do something nice </dtml-if> </dtml-in> would work, whereas <dtml-if "id() == 'somestring'"> would break if there are objects whose ids are not methods (assuming File is one of them, which I wouldn't know) So the different forms are (actually there are some more, but they do not matter here): <dtml-var id> <dtml-var "id"> <dtml-var "_['id']"> <dtml-var "id()"> <dtml-var "_[id]"> will give you an error Now that was probably more English than you'd hoped for hth Rik
----- Original Message ----- From: Timothy Wilson <wilson@visi.com>
On Wed, 24 May 2000, Rik Hoekstra wrote:
..
Ok.. this is really dumb, but for some reason I can't get this to work.
<dtml-if "id=='index_html'">
I believe this should be
<dtml-if "_['id']=='index_html'">
I wonder if someone would be kind enough to translate Rik's code into Enlish for me. I know that expressions inside "" are Python, but what is the function of the [] and _?
The special "namespace" variable, "_" It is useful to access the variables with special names, like "sequence-index" For example: <dtml-if "sequence-index==3" > will not work "sequence MINUS index==3" :-) You have to use <dtml-if "_['sequence-index']==3" > In fact "_['id']" is the some thing with "id" , I presume (or maybe I'm wrong). so, is no difference between <dtml-if "id=='index_html'"> && <dtml-if "_['id']=='index_html'"> Find more @: http://www.zope.org/Documentation/Guides/DTML-HTML/DTML.5.3.2.3.html Marcel
participants (5)
-
J. Atwood -
Marcel Preda -
Phil Harris -
Rik Hoekstra -
Timothy Wilson