[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 - [EMAIL PROTECTED] 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 )
Re: [Zope] Feeling like a newbie.. document id if statement?
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 [EMAIL PROTECTED] - Original Message - From: "J. Atwood" [EMAIL PROTECTED] To: [EMAIL PROTECTED] 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 - [EMAIL PROTECTED] 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 ) ___ Zope maillist - [EMAIL PROTECTED] 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 )
Re: [Zope] Feeling like a newbie.. document id if statement?
- Original Message - From: Timothy Wilson [EMAIL PROTECTED] 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 ___ Zope maillist - [EMAIL PROTECTED] 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 )
Re: [Zope] Feeling like a newbie.. document id if statement?
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 ___ Zope maillist - [EMAIL PROTECTED] 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 )