[Zope] DTML type casting? or something? / LocalFS subdirectory exists test

Thomas B. Passin tpassin@mitretek.org
Wed, 24 Apr 2002 10:30:58 -0400


[davis marques]

> I'm having a DTML problem here.  I'm trying to test whether a subdirectory
> (whose id=ProjectID) exists under a LocalFS object.
>
> <dtml-with ProjectID>
>       <dtml-if "'&dtml-ProjectID;' in projectfiles.fileIds()">
>             The directory "<dtml-var ProjectID>" exists
>       <dtml-else>
>             "<dtml-var ProjectID>" does not exist
>       </dtml-if>
> </dtml-with>
>
> When I manually enter a value in place of ProjectID it works fine (ex.
> "'202006' in projectfiles.filesIds()").  When I use &dtml-ProjectID; it
> doesn't work.  I presume that the value of ProjectID is not being
translated
> into an appropriate format for the expression to work, but I don't know
how
> to test this or to resolve this.  Any thoughts?  Better ways to do this?
>

Don't use the &dtml-xxx; within a dtml statement.  The dtml code already
knows about ProjectID, just use its name.

Aslo, I don't see the purpose of the dtml-with statement.  You would
normally use that to establish a namespace after which you would not
continue to use its.  That does not appy here, as far as I can see.

 You could use the entity syntax in some of your other expressions, if you
like.  So it seems that this should do the job:

       <dtml-if "ProjectID in projectfiles.fileIds()">
             The directory "&dtml-ProjectID;" exists
       <dtml-else>
             "&dtml-ProjectID;" does not exist
       </dtml-if>

I'm assuming that ProjectID is some simple variable or property that is
known to the document, which seems to be how you are using it.  If it
weren't known, the dtml-with expression would have given an error.

Cheers,

Tom P