Fog Creek Software
Discussion Board




Knowledge Base
Documentation
Terry's Tips
Darren's Tips

foreach-ing thru a list of images

I've been trying to figure how to write a foreach loop which displays all the images in my /images folder.  Can someone point me to an example?

thanks

Joel Goldstick
Monday, September 02, 2002

Here is what I am playing with: 


$foreach x in (folder "Images")$} <A href="{$x.link$}">image filename is: {$x.filename $} </A>{$next$}

Joel Goldstick
Monday, September 02, 2002

I think the "foreach" only looks at articles.

There have been a lot of requests for managing/displaying images.  Many folks put their images in the extra fields of articles or in the article themselves.  I'm not sure if that's what you want but:

Deb did a great job of it here:
http://www.lakemonticelloproperties.com/listingsa.htm

Here is a discussion about how Deb did it:
http://discuss.fogcreek.com/CityDesk/default.asp?cmd=show&ixPost=1481&ixReplies=8

This is how Michael Prior suggested:
http://tk-jk.net/city/Bagofscripts/fog0000000083.htm

Here is a download from FogCreek:
http://tk-jk.net/city/RealEstate.cty

tk
Monday, September 02, 2002

Joel, I'm sure there are better ways of doing it, but for what it's worth this is how I did it:

Site index.html has:

{$foreach x in (keyword_contains "(Index)")$}

{$x.headline$}

{$next$}

Each folder (e.g. "First Set O Pics") has one file with the same name (e.g. "First Set O Pics"), one file named "Pics", and one file per image with only the image in the body.

The file named "First Set O Pics" has the keyword "(Index)" and in the body has:

{$foreach x in (folder "firstsetopics")$}

{$x.extra2$}

{$x.extra1$}

{$next$}

The only file in each folder with nonblanks in the extra2 and extra1 fields is the "Pics" file. The extra2 field is a breadcrumb, and is Home --> First Set O Pics, with "Home" linked to index.html. The extra1 field has thumbnails of each image, each of which link to its respective file. Putting the thumbs in the extra1 field like this and then calling them as shown above is how I got the thumbs to display in rows/columns.

The "First Set O Pics" file uses a template called "Thumbs" that only has {$ .body $} in the normal view.

The "Pics" file and each image file use the "Simple" template, which has a breadcrumb like this: Home --> {$.teaser$}. "Home" links to index.html, and {$.teaser$} is populated by the teaser field in each image file, each of which is "First Set O Pics" linked to the "First Set O Pics" file. Beneath the breadcrumb is a two-row table with {$ .headline $} centered in the top row and {$ .body $} centered in the bottom row.

Each image file has the full-size image in the body. The "Pics" file has nothing in the body.

Gilles
Wednesday, September 04, 2002

*  Recent Topics

*  Fog Creek Home