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

Reply via email to