Fog Creek Software
Discussion Board




Knowledge Base
Documentation
Terry's Tips
Darren's Tips

Graphic Collections

Here's what I'd like to put in my template:

<script language="javascript">
//other stuff here

//fill an array with filenames, in this case a collection of graphics.
var image_index = 0;
image_list = new Array();
{$ foreach x in (folder "{$.headline$}") $}
    {$.filename$}<br>
    image_list[image_index++] = new imageItem("{$.headline$}/{$x.filename$}");
{$ next $}
var number_of_image = image_list.length;
//more other stuff here
</script>

There are two problems with this. First, the (folder...) statement does not take variables the "." (this folder). Second, CityScript does not seem to recognize the existence of non-article extensions (in this case, I'm working with *.jpg).

I can see solutions to this, but not anything that I feel comfortable with in a situation where the client will handle most maintenance tasks. Specifically, the client will be adding and removing graphics files on a regular basis and would like the 3 or 4 images to be randomly cycled (hence the need for an array of image filenames).

Perhaps someone out there already has elegant (or at least useful) solutions?

Ron Porter
Monday, May 12, 2003

Proof-reading, Ron!

'... does not take variable OR the "."'

'... 3 or 4 of the dozens of images...

Ron Porter
Monday, May 12, 2003

I'd like to do the same thing.  I hardcoded my array with magic names, but Ron's loop is better.

www.daliblume.com
Monday, May 12, 2003

Unfortunately, CityScript can't loop over non-article files.

One solution is to use PHP to construct the list of images. It can just look in the image directory on the server, and pull in all the *.jpg files. PHP would also allow you to do things like randomly pick one image, so that they change each time you visit the page.

Darren Collins
Monday, May 12, 2003

Another solution is to have a graphic collection folder containing articles with images in the article's fields. 

For example, you could put the caption in teaser, the thumbnail in extra1 and the larger image in extra2.  In the beta, you can create a new template, changing the field names to match the actual content.

You can then loop over the folder using the foreach or nextlink|prevlink  loops.

David Burch
Friday, May 16, 2003

I too wanted to use image files in my citydesk foreach loop, but since they aren't articles, that won't work.

So, in my images directory I created blank articles with no template (no extension to name!) with the same names as the image files.  Then I looped on the articles in the folder.  This takes up dreaded "file count" but it worked for me:

{$ forEach x in (folder "Images") $}
<IMG height="100px" width="120px" alt="{$x.headline$}" src="Images/{$x.fileName$}.jpg" title="{$x.headline$}">
{$ next $}

If you need your client to update, they will have to insert the image files in the directory and create an identically named file -- not too bad really.  No javascript or server scripting involved.

Joel Goldstick
Friday, May 16, 2003

That looks like the answer! I was fooling around with a variety of similar solutions, but it never occurred to me to use the filename.

Ron Porter
Saturday, May 17, 2003

*  Recent Topics

*  Fog Creek Home