Hi All: I am trying to download files (with standardized filenames) to specific subdirectories with a form that calls a dtml document for processing, but the code breaks at the dtml-elif phrase: -------- <dtml-var standard_html_header> <h2><dtml-var title></h2> <dtml-let fname="_.string.split(myfile.filename,'\\')[-1]"> <dtml-let filename="_.string.split(fname,'.html')[0]"> <dtml-if expr="filename[3:6]=='do_'"><dtml-let dir="do_"> <dtml-elif expr="filename[3:6]=='aa_'"><dtml-let dir="aa_"> <dtml-else><dtml-let dir="vth"> <dtml-with avc> <dtml-call expr="dir.manage_addDTMLDocument(filename,mytitle)"> </dtml-with> </dtml-let> </dtml-if> </dtml-let> </dtml-let> <dtml-var showFiles> <dtml-var standard_html_footer> ------- with error message: Unexpected tag, for tag <dtml-elif expr="filename[3:6]=='aa_'"> However, the code function ok if dtml-elif and dtml-else lines are omitted. I cannot understand why and would appreciate any solutions. Tom Germaine ~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~ Tom Germaine System Administrator UPEI Access Services tgermaine@upei.ca 566-0465 ~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
You cant put unmatched lets inside an if. Consider using Python. If you have to use DTML you have to set variables into the REQUEST. -- Andy McKay @gmweb Consulting http://www.agmweb.ca
I believe that it is complaining that it expects to find a </dtml-let> before the <dtml-elif>. if you change the indenting like this: <dtml-let fname="_.string.split(myfile.filename,'\\')[-1]"> <dtml-let filename="_.string.split(fname,'.html')[0]"> <dtml-if expr="filename[3:6]=='do_'"> <dtml-let dir="do_"> <dtml-elif expr="filename[3:6]=='aa_'"> <dtml-let dir="aa_"> <dtml-else> <dtml-let dir="vth"> <dtml-with avc> <dtml-call expr="dir.manage_addDTMLDocument(filename,mytitle)"> </dtml-with> </dtml-let> </dtml-if> notice that I haven't added anything but whitespace. but say that the <dtml-if> resolves to 'TRUE', it enters the <dtml-let> block and the first tag is a <dtml-elif>. Thats the first thing that popped into my head anyhow, I've been wrong before =)> Tom Germaine wrote:
Hi All:
I am trying to download files (with standardized filenames) to specific subdirectories with a form that calls a dtml document for processing, but the code breaks at the dtml-elif phrase: -------- <dtml-var standard_html_header>
<h2><dtml-var title></h2>
<dtml-let fname="_.string.split(myfile.filename,'\\')[-1]"> <dtml-let filename="_.string.split(fname,'.html')[0]">
<dtml-if expr="filename[3:6]=='do_'"><dtml-let dir="do_"> <dtml-elif expr="filename[3:6]=='aa_'"><dtml-let dir="aa_"> <dtml-else><dtml-let dir="vth">
<dtml-with avc> <dtml-call expr="dir.manage_addDTMLDocument(filename,mytitle)"> </dtml-with>
</dtml-let> </dtml-if>
</dtml-let> </dtml-let>
<dtml-var showFiles> <dtml-var standard_html_footer> ------- with error message: Unexpected tag, for tag <dtml-elif expr="filename[3:6]=='aa_'">
However, the code function ok if dtml-elif and dtml-else lines are omitted.
I cannot understand why and would appreciate any solutions.
Tom Germaine
~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~ Tom Germaine System Administrator UPEI Access Services tgermaine@upei.ca 566-0465 ~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
-- Don't let rationalization stand in the way of your paranoia. Jason Bush | jason@nol.org Nebraska Online | http://www.nol.org
It's looking for the close of the <dtml-let> statement. The best thing to do would be: <dtml-if expr="filename[3:6]=='do_'"><dtml-call "REQUEST.set('dir', 'do_')"> <dtml-elif expr="filename[3:6]=='aa_'"><dtml-call "REQUEST.set('dir', 'aa_')"> <dtml-else><dtml-call "REQUEST.set('dir', 'vth')"> Rick Tom Germaine wrote:
Hi All:
I am trying to download files (with standardized filenames) to specific subdirectories with a form that calls a dtml document for processing, but the code breaks at the dtml-elif phrase: -------- <dtml-var standard_html_header>
<h2><dtml-var title></h2>
<dtml-let fname="_.string.split(myfile.filename,'\\')[-1]"> <dtml-let filename="_.string.split(fname,'.html')[0]">
<dtml-if expr="filename[3:6]=='do_'"><dtml-let dir="do_"> <dtml-elif expr="filename[3:6]=='aa_'"><dtml-let dir="aa_"> <dtml-else><dtml-let dir="vth">
<dtml-with avc> <dtml-call expr="dir.manage_addDTMLDocument(filename,mytitle)"> </dtml-with>
</dtml-let> </dtml-if>
</dtml-let> </dtml-let>
<dtml-var showFiles> <dtml-var standard_html_footer> ------- with error message: Unexpected tag, for tag <dtml-elif expr="filename[3:6]=='aa_'">
However, the code function ok if dtml-elif and dtml-else lines are omitted.
I cannot understand why and would appreciate any solutions.
Tom Germaine
~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~ Tom Germaine System Administrator UPEI Access Services tgermaine@upei.ca 566-0465 ~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
_______________________________________________ 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 )
oops... sorry .. let's try that again: <dtml-if expr="filename[3:6]=='do_')"> <dtml-call "REQUEST.set('dir', 'do_')"> <dtml-elif expr="filename[3:6]=='aa_'"> <dtml-call "REQUEST.set('dir', 'aa_')"> <dtml-else> <dtml-call "REQUEST.set('dir', 'vth')"> </dtml-if> There. That looks better. Was in too big of a hurry. The point here is that you need to push those variables to REQUEST if you need access to them outside the <dtml-if> statements. Rick D. Rick Anderson wrote:
It's looking for the close of the <dtml-let> statement. The best thing to do would be:
<dtml-if expr="filename[3:6]=='do_'"><dtml-call "REQUEST.set('dir', 'do_')"> <dtml-elif expr="filename[3:6]=='aa_'"><dtml-call "REQUEST.set('dir', 'aa_')"> <dtml-else><dtml-call "REQUEST.set('dir', 'vth')">
Rick
Tom Germaine wrote:
Hi All:
I am trying to download files (with standardized filenames) to specific subdirectories with a form that calls a dtml document for processing, but the code breaks at the dtml-elif phrase: -------- <dtml-var standard_html_header>
<h2><dtml-var title></h2>
<dtml-let fname="_.string.split(myfile.filename,'\\')[-1]"> <dtml-let filename="_.string.split(fname,'.html')[0]">
<dtml-if expr="filename[3:6]=='do_'"><dtml-let dir="do_"> <dtml-elif expr="filename[3:6]=='aa_'"><dtml-let dir="aa_"> <dtml-else><dtml-let dir="vth">
<dtml-with avc> <dtml-call expr="dir.manage_addDTMLDocument(filename,mytitle)"> </dtml-with>
</dtml-let> </dtml-if>
</dtml-let> </dtml-let>
<dtml-var showFiles> <dtml-var standard_html_footer> ------- with error message: Unexpected tag, for tag <dtml-elif expr="filename[3:6]=='aa_'">
However, the code function ok if dtml-elif and dtml-else lines are omitted. I cannot understand why and would appreciate any solutions.
Tom Germaine
~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~ Tom Germaine System Administrator UPEI Access Services tgermaine@upei.ca 566-0465 ~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
_______________________________________________ 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 )
_______________________________________________ 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 )
You have an opening dtml-let tag in one element and the closing one for it in another element. The dtml expresssion is not well-formed. The parser expects to have your <dtml-let dir="do_"> and similar elements to nest properly. That is why you get the error. DTML does not work by building a string using the conditionals and then evaluating that string (in which case your approach nmight work). It effectively builds a tree, and you cannot have part of a branch, only whole branches or none. You need to nest your expressions completely You can have something like this: <dtml-if "filename[3:6]=='do_'"> <dtml-let dir="do_"> <!--do something with "do_"--> </dtml-let> <dtml-elif "filename[3:6]=='aa'"> <dtml-let dir="aa_"> ..... </dtml-let> <dtml-else> ..... </dtml-if> Cheers, Tom P [Tom Germaine]
<dtml-if expr="filename[3:6]=='do_'"><dtml-let dir="do_"> <dtml-elif expr="filename[3:6]=='aa_'"><dtml-let dir="aa_"> <dtml-else><dtml-let dir="vth">
<dtml-with avc> <dtml-call expr="dir.manage_addDTMLDocument(filename,mytitle)"> </dtml-with>
</dtml-let> </dtml-if>
</dtml-let> </dtml-let>
<dtml-var showFiles> <dtml-var standard_html_footer> ------- with error message: Unexpected tag, for tag <dtml-elif expr="filename[3:6]=='aa_'">
However, the code function ok if dtml-elif and dtml-else lines are omitted.
I cannot understand why and would appreciate any solutions.
On Fri, Aug 02, 2002 at 01:28:45PM -0300, Tom Germaine wrote:
Hi All:
I am trying to download files (with standardized filenames) to specific subdirectories with a form that calls a dtml document for processing, but the code breaks at the dtml-elif phrase: -------- <dtml-var standard_html_header>
<h2><dtml-var title></h2>
<dtml-let fname="_.string.split(myfile.filename,'\\')[-1]"> <dtml-let filename="_.string.split(fname,'.html')[0]">
<dtml-if expr="filename[3:6]=='do_'"><dtml-let dir="do_">
Stop right there. <dtml-let> must be closed before you can go into another logical block such as <dtml-elif>. It seems weird, I know, but that's the way it works. Your first instinct might be to get around this problem by duplicating your <dtml-call> code in each part of the if/elif/else. But I wouldn't do that - duplicated code is a sign that there must be a better way. Instead, get rid of the dtml-if entirely and try something like this: (untested) <dtml-with avc> <dtml-call expr="_.addMyDoc(REQUEST, _.getitem('mytitle)')"> </dtml-with> Now write a script (python) called addMyDoc in the same folder as this dtml code. On the parameter list in the management interface, add: REQUEST=None, mytitle="" In the body of the script, write something like this (untested): # note: I'm not sure about mytitle - it's not clear to me # in your code where it comes from. # If it's in the request, then uncomment the next line, and # remove the second parameter from the dtml-call expression: # mytitle = REQUEST['mytitle'] filename = REQUEST['filename'] if filename[3:6] == 'do_': dir = getattr(container, 'do_') elif filename[3:6] == 'aa_': dir = getattr(container, 'aa_') else: dir = getattr(container, 'vth') dir.manage_addProduct['OFSP'].manage_addDTMLDocument(mytitle, filename) return "" # end of script. -- Paul Winkler home: http://www.slinkp.com "Muppet Labs, where the future is made - today!"
As a humourous aside, this whole thread probably wouldn't have happened had you done the 'right thing' and uses a Script (Python) for this logic. Still, cheers for the laughs involved in reading peopel squabling over where that </dtml-let> and <dtml-call "REQUEST.set(x,y)"> should go, it's made my morning :-) cheers, Chris
participants (7)
-
Andy McKay -
Chris Withers -
D. Rick Anderson -
Jason Bush -
Paul Winkler -
Thomas B. Passin -
Tom Germaine