hmm. I tried it, but getting some errors. I know the file exists cause I am looking on the server.
If I use the relative path, I get: file error - /xml/national.xml: No such file or directory at /app/shared/lib/perl/Cntrl.pm line 285 If I use the absolute path, I get: file error - no providers for file prefix 'http' at /app/shared/lib/perl/Cntrl.pm line 285any other possible tt tricks to get the file info? thanks --- On Wed, 6/22/11, Ronald J Kimball <[email protected]> wrote: From: Ronald J Kimball <[email protected]> Subject: Re: [Templates] Way to test if a file has content or has a size greater than 0 in TT?? To: "Summer" <[email protected]> Cc: [email protected] Date: Wednesday, June 22, 2011, 7:29 AM You could do this: [% file = INSERT "path/to/file" %][% file.length %] Note that this will throw an error if the file does not exist. You can use TT's TRY/CATCH to catch that error. However, reading the entire file into memory just to find out its size is kind of a heavy solution. Another option would be to pass a method to the template that just checks the size of the file with -s. Ronald On Tue, Jun 21, 2011 at 9:38 PM, Summer <[email protected]> wrote: Hey All, Given the normal distribution of template tookit, is there a way to test to see if a file on the server has any content in it? I am requesting xml via ajax and in some instances a file or two might not have any content though it still exists in the directory, so I don't even wanna go and request the file if there is a way I can (in template toolkit) determine if the file even exists or has any content. Is there any way to determine if somexmlfile.xml has some content associated with it? Assign it to a var and then test the length of the var or somesuch? thanks. _______________________________________________ templates mailing list [email protected] http://mail.template-toolkit.org/mailman/listinfo/templates
_______________________________________________ templates mailing list [email protected] http://mail.template-toolkit.org/mailman/listinfo/templates
