[ZPT] tal:condition question for TALES
Kim Groves
digicate at netspace.net.au
Sat Sep 17 02:13:54 EDT 2005
Hi,
Is it possible to use the existence of a file on the webserver as a
condition in a TALES expression?
I have read many pages on Zope/TAL/TALES and they seem to indicate that it
is, however none of the offered syntaxes seem to operate correctly.
Here is the scenario:
We have a directory on the webserver: /information
which contains a set of pdf documents. The application is a cart, eg
webshop.
The products on the site may or may not have an associated pdf file. The
name of the pdf is the same as the Product Id.
eg:
<tr><td colspan=4><a target="" href="" tal:define="pdf_path
string:/information/${product/pid}.pdf"
tal:condition="exists:pdf_path" tal:attributes="href pdf_path; target
pdf_path">Information Sheet</a></td></tr>
If the pdf file does exist, then the link will take the visitor to the file,
so that bit works okay.
However, if the pdf does not exist, we are still getting a link on the page,
and this link opens a new window with an error message from the server, eg
"Requested URL not found.
The requested URL "www.domain.com/information/75080.pdf" was not found in
this shop.
You can return to the shop front by clicking here"
I asked one of the people at the company that operates the web site for
ideas, they suggested defining a property on each product with the pdf href
(if available), however there are hundreds of pdf files so this would not be
feasible/fun. We have an inhouse server with a different site using php and
it is able to test for the existence of the file before showing the link on
the returned page.
Can anybody provide a concrete example of the correct syntax for checking
for a path using TALES?
Is it possible the server we are using has been customised/modified so that
the expressions do not behave as you would normally expect?
I have also tried tal:condition:"path:root/information/${product/pid}.pdf"
but this either generates an error page or always returns true, whether the
file exists or not.
Thanks
Kim Groves
More information about the ZPT
mailing list