Fog Creek Software
Discussion Board




Knowledge Base
Documentation
Terry's Tips
Darren's Tips

check for image?

Is there a way to check for an image, and only have the <img> tag inserted when there actually is an image to insert, so as not to show a placeholder when a certain folder doesn't contain an image?

like so:
{$foreach 1 x in (and (thisFolder) (fileName "image.jpg")) $}

<img src=........

{$ endif $}

...but this doesn't work

Anyone?

Rogn

Rognvaldr
Tuesday, June 22, 2004

If you reference the image through an article (magic name or image inserted into field) you can check for an article field being empty or not, i.e.

{$ if blank .author $}.... {$ endif $}...{$ if nonblank .author$}

or in foreach loops

{$ if blank x.author $}.... {$ endif $}

Hope that helps.

Patrick Thomas
http://www.telepark.de

Patrick Thomas
Tuesday, June 22, 2004

Well, I found a (somewhat clumsy) solution. In the folders I want to check for a certain jpg, I create an article, say, "_image", and add the jpg-file to its body (repeat procedure for all folders I want to use this on).

In my template I then use:

{$foreach 1 x in (and (thisFolder)(fileName "_image")) $}
{$ include "_image" $}
{$ endif $}


I really shouldn't need to resort to such clumsy methods, but since my website is static, it is a one time job... So, unless anyone comes up with a better solution, I'll probably go for it.

Rogn

Rognvaldr
Tuesday, June 22, 2004

Thanks for the answer, I didn't see it until after I posted my own reply.

I really don't want to embed an image inside an article, but if that's the way to go... soit.

Rogn

Rognvaldr
Tuesday, June 22, 2004

correction, that would be:

{$foreach 1 x in (and (thisFolder)(fileName "_image")) $}
{$x.body$}
{$ endif $}

Rogn

Rognvaldr
Tuesday, June 22, 2004

*  Recent Topics

*  Fog Creek Home