Fog Creek Software
Discussion Board

Knowledge Base
Terry's Tips
Darren's Tips

Loops Of Fury

Being the CD newbie I am, I am currently trying a lot of things with the software and occasionally hitting a glass ceiling. When that happens, it makes me wonder whether I'm just stupid or whether I've hit a limitation in CityScript.

The following two worries seem to be related:

(1) I have this gallery section where the index page offers thumbnails of what my hubristic superego wants to call "artwork". So there is a table with four columns which gets populated with linked thumbnails. So far, this has been happening by hand, but of course now I want The Machine to do it.

CityDesk should take the first four articles (i.e. gallery entries) and place them in one row, the next four articles in another row and so on. If it can't fill a row with thumbnails, it should output blank TD tags to fill the row. I don't see a way of doing this with CS.

( The URL for the current, static, hand-written page is )

(2) I would like CD to pull the articles of one folder together into a file. However, and this is where I fail to see the way to do it, since the HTML files would get too long I'd appreciate it if CD would split the output into several HTML files: Stick the first five articles in one HTML file, the next five into another, and so on. Once again, I'm stuck.

Am I trying to do impossible things or am I just impossibly dense?

Wednesday, August 27, 2003

You're not dense. You can't do "first 4, second 4, etc." with CityScript yet. So, there is not a CityScript way to do either of your 1 or 2.

In my case, I've tried to quit thinking about how I can make CityDesk conform to my design ideas and tried instead to think about doing things a little differently so I can take advantage of CityDesk. Of course thinking is not my strong point anyway.

There have been lots of suggestions that CityDesk manage photo albums and the like.

Wednesday, August 27, 2003

P.S. I love the art. Maybe you can just keep handcoding that gallery page and let CityScripts do whatever else it can for you.

Wednesday, August 27, 2003

I'm not sure I understand your part 2, but as to part 1:

You can do it with CSS very nicely.  Float your images left.  Make a loop with CityScript to add all of your thumbnails to the page.  If you put the pictures inside a div with a width of something that will hold just 4 images, then each 'row' will hold 4 images.  If you don't bother with the div, depending on how wide the user's browser is, they will see as many pictures as fit on a line.  Then next ones will be below

I have images in /Images.  I made a folder under that called Links.  I created articles for each image in Links.  Then I copied the magic name of an image, and pasted it into extra1 in one of the link files.  Then, on to the next image and next article.  This would be a pain the first time, but adding a few images at a time wouldn't be so bad. 

{$ foreach x in (folder "/Images/Links") $}
<img src="{$x.extra1$}" style="float: left; padding: 4px; border: 1px solid red;">
{$next $}

I made a little test file here.  Resize your browser to see how the images move to the next row.

Joel Goldstick
Wednesday, August 27, 2003

Now, I understand part 2.  You can do a foreach 5 x to make a loop that contains the first 5 articles.  As you add articles to the folder, it will keep picking the first 5 so you can sort by date if you like to get the most recent 5.  Then, you can make a new foreach loop to include links to all of the articles.  Just title it archives, or something.  When the user clicks an archive article, only 1 at a time will be displayed.  Not exactly what you want, but maybe its close?

Joel Goldstick
Wednesday, August 27, 2003

Is it possible to put a jpg in the EXTRA1 field, or in another field.

Then you can create a ForEach loop that calls regular CD articles.

I suggest this method because heck golly V2 allows unlimited articles!

We're all trying to push CD, so keep the requests coming.


Bob Bloom
Wednesday, August 27, 2003

Ok, I had to try.

YES, using the INSERT menu item, I put a jpg in the EXTRA1 field.

I haven't tried a ForEach loop so let us know how it went.


Bob Bloom
Wednesday, August 27, 2003

You knew I had to try a ForEach loop. Here it is:

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

It works!

Yeeee--hawww. I'm keeping this trick in my back pocket.

Let us know how you implement it on your site!


Bob Bloom
Wednesday, August 27, 2003

Thanks for all the responses, I figured as much. So basically I'll have to go the CSS route after all, which I didn't want to because of backwards compatibility.

Well, after three days with CD, I already have my wish list in place. That certainly didn't take long. :-)

- a conditional counter: do (loop) for every n articles in (folder "folder") -- or something like that.

This would offer a way to split up article archives.

- exception handing: if n is smaller than x do (loop) until n == x

This would offer a way to fill up empty table columns with cells.

But by now I'm confident that when CD gets to the point of supporting this kind of functionality, the issue'll be solved far more elegantly than what I've outlined above.

Until then, I will make do with what I have. Again, thanks for all your help! The breadcrumbs solution works great, by the way.

Thursday, August 28, 2003

*  Recent Topics

*  Fog Creek Home