Variable substitution of <dtml-in> Attributes
Hi all, This doesn't appear to be possible but I'm just confirming. I have this line of code: <dtml-in expr="PARENTS[0].objectValues('Folder')" sort=id> I'd like to be able to substitute the Attributes as a string. For example a dtml method called sort_order may contain the string: reverse sort=id Then I would substitute that in at runtime. It might look something like this: <dtml-in expr="PARENTS[0].objectValues('Folder')" &dtml-sort_order;> However this and similar attempts gives me a Document Template Parse Error. Thanks, Adam
This doesn't appear to be possible but I'm just confirming. I have this line of code:
<dtml-in expr="PARENTS[0].objectValues('Folder')" sort=id>
I'd like to be able to substitute the Attributes as a string. For example a dtml method called sort_order may contain the string:
reverse sort=id
Then I would substitute that in at runtime. It might look something like this:
<dtml-in expr="PARENTS[0].objectValues('Folder')" &dtml-sort_order;>
However this and similar attempts gives me a Document Template Parse Error.
This is definitely not possible with the current dtml-in tag. The dtml-tag does not provide "reverse_expr=", "sort_expr=", and so forth (like to the dtml-tree tag). I see two options for you: a) Use the new code from "lib/python/DTMLTemplate/sequence", and pass the "untouched" sequence (see http://www.zope.org/Members/michel/ZB/AppendixA.dtml - "sequence - DTML Sequence Functions") b) use a python script :-) hth, Danny
On Tue, 2001-11-06 at 19:04, Danny William Adair wrote:
This is definitely not possible with the current dtml-in tag. The dtml-tag does not provide "reverse_expr=", "sort_expr=", and so forth (like to the dtml-tree tag).
b) use a python script :-)
Thanks for the info Danny. You're right about using a Python script. Here is the original dtml method that I wrote: <dtml-if expr="_.len(PARENTS)>3"> <ul><li><a href="..">Up one level...</a></li></ul> </dtml-if> <dtml-comment> I can't just have unsorted list items above and below because <ul></ul> is a breach of HTML 4.01! </dtml-comment> <dtml-call "REQUEST.set('count', 0)"> <dtml-in expr="PARENTS[0].objectValues('Folder')" sort=id> <dtml-if expr="id!='Files'"> <dtml-call "REQUEST.set('count', count+1)"> <dtml-if expr="count==1"> <ul> </dtml-if> <li><a href="&dtml-absolute_url;"><dtml-var expr="underscore2space(foldername=id)"></a><br /><br /></li> </dtml-if> </dtml-in> <dtml-if expr="count>0"> </ul> </dtml-if> This is the equivalent functionality written as a Python script: # Import a standard function, and get the HTML request and response objects. from Products.PythonScripts.standard import html_quote request = container.REQUEST RESPONSE = request.RESPONSE import string if len(request.PARENTS)>3: print '<ul><li><a href="..">Up one level...</a></li></ul>' # Note: I can't just have unsorted list items above and below because <ul></ul> is # a breach of HTML 4.01! folders=request.PARENTS[0].objectValues('Folder') folderids=[element.id for element in folders] folderurls=[element.absolute_url() for element in folders] #Now I'm going to generate a dictionary with the folder ids as the keys folderdict={} for key, value in map(None, folderids, folderurls): folderdict[key]=value #Remove folder 'Files' from the menu try: del folderdict['Files'] except: pass sortedids=folderdict.keys() sortedids.sort() if len(folderdict.keys())>0: print '<ul>' for folder in sortedids: nounderscoreid=string.replace(folder, '_', ' ') print '<li><a href="'+folderdict[folder]+'">'+nounderscoreid+'</a><br /><br /></li>' print '</ul>' return printed I think the dtml method stacks up surprisingly well! However I had the problem that I couldn't expand the dtml method to do other type of sorting. This solves that problem. If anyone can show a better rewrite of my Python script I won't be offended. This isn't an essential question but I noticed if: folders=[<Folder instance at 88d95d0>, <Folder instance at 8abd0d8>, <Folder instance at 8801408>,...] print folders[1].id gives me the id of the second element. But: print folders[1].id() gives me the error: Error Type: TypeError Error Value: object of type 'string' is not callable This seems to be inconsistent with: print folders[1].absolute_url() If someone could point out why folders[1].id() doesn't work I'd appreciate it. Regards, Adam
This is definitely not possible with the current dtml-in tag. The dtml-tag does not provide "reverse_expr=", "sort_expr=", and so forth (like to the dtml-tree tag).
On the contrary, you can use sort_expr with dtml-in. Look at the following method: <dtml-unless sort_by> <dtml-call "REQUEST.set('sort_by','title')"> </dtml-unless> <dtml-in Catalog_Org size=50 start=query_start sort_expr="sort_by"> <dtml-if sequence-start> <dtml-if previous-sequence> ... ... ... <table width="95%"> <tr valign="top"> <td><b>Name<br><img src="/img/sp_white.gif" width="1" height="6"></b></td> <td><b><a href="org_list?sort_by=title&facility_type=&dtml-facility_type;&org_type=&dtml-org_type;">Organisation <dtml-if "sort_by=='title'"> <img src="/img/arrow_down" border="0"> </dtml-if> </a></b></td> <td><b><a href="org_list?sort_by=city&facility_type=&dtml-facility_type;&org_type=&dtml-org_type;">City <dtml-if "sort_by=='city'"> <img src="/img/arrow_down" border="0"> </dtml-if> </a></b></td> </tr> ... ... ... -- Milos Prudek
On Wednesday 07 November 2001 08:49, Milos Prudek wrote:
This is definitely not possible with the current dtml-in tag. The dtml-tag does not provide "reverse_expr=", "sort_expr=", and so forth (like to the dtml-tree tag).
On the contrary, you can use sort_expr with dtml-in.
Whoops. You're totally right. I'm wrong and sorry. Still, this only allows the sort attribute to be variable. The new "sequence" module has got it all: <dtml-in expr="_.sequence.sort(objectValues(), (('title', 'nocase'), ('bobobase_modification_time', 'cmp', 'desc') ))"> <dtml-var title><dtml-var bobobase_modification_time> <br /> </dtml-in> More in http://www.zope.org/Members/michel/ZB/AppendixA.dtml (that's been updated) Thx, Danny
Adam, Do it in your ZSQL method instead. That way you pass: <dtml-in "blah(something=something, order='desc', sort='field')"> Then in your sql method: Select * from blah where foo=<dtml-sqlvar something type=string> Order by <dtml-var sort> <dtml-var order> I use is a few times, quite nicely. Paul Zwarts -----Original Message----- From: zope-admin@zope.org [mailto:zope-admin@zope.org] On Behalf Of Adam Warner Sent: Tuesday, November 06, 2001 6:30 AM To: zope@zope.org Subject: [Zope] Variable substitution of <dtml-in> Attributes Hi all, This doesn't appear to be possible but I'm just confirming. I have this line of code: <dtml-in expr="PARENTS[0].objectValues('Folder')" sort=id> I'd like to be able to substitute the Attributes as a string. For example a dtml method called sort_order may contain the string: reverse sort=id Then I would substitute that in at runtime. It might look something like this: <dtml-in expr="PARENTS[0].objectValues('Folder')" &dtml-sort_order;> However this and similar attempts gives me a Document Template Parse Error. Thanks, Adam _______________________________________________ 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 )
Adam Warner wrote:
Hi all,
This doesn't appear to be possible but I'm just confirming. I have this line of code:
<dtml-in expr="PARENTS[0].objectValues('Folder')" sort=id>
I'd like to be able to substitute the Attributes as a string. For example a dtml method called sort_order may contain the string:
reverse sort=id
Then I would substitute that in at runtime. It might look something like this:
<dtml-in expr="PARENTS[0].objectValues('Folder')" &dtml-sort_order;>
However this and similar attempts gives me a Document Template Parse Error.
It's possible, IIRC you have to use sort_expr instead of sort. See the source-code of the ZMI, it's used there (for dynamic sorting of the folder contents) cheers, oliver
participants (5)
-
Adam Warner -
Danny William Adair -
Milos Prudek -
Oliver Bleutgen -
Paul Zwarts