Fog Creek Software
Discussion Board




Knowledge Base
Documentation
Terry's Tips
Darren's Tips

Scripting question

Ok, on my website, which I am trying to convert to use with city desk, I have two main topic areas, security issues and Windows tips.

Gaah I was actually typing in one problem when I figured it out! I'm really enjoying getting to grips with citydesk but I want to see if I can knock all my problems on the head with the free edition before getting one of the "pay for" ones - hope thats ok ;-).

Anyway, one question I have about scripting - I have each section's "front page" showing the articles just in that section - what would be the easiest way for the index page to always show the last 2 or 3 articles in each section, for example, or if that's not possible, how about those created in the last 2 weeks?

Robert Moir
Sunday, January 13, 2002

If you store the articles for each section in their own folders, for example, a folder called "windowsTips", you could make links to the last 3 articles in that folder as follows:

{$ foreach 3 x in (folder "windowsTips") sortDescendBy .filedDate $}
<a href="{$x.link$}">{$x.headline$}</a><br>
{$x.next$}

Joel Spolsky
Sunday, January 13, 2002

Joel
Thanks for the speedy response

When I try your code as given I get an error when I try to preview the site
"Script Error: illegal identifier "next" in \index.html"

I also get the links showing as such:
"<a href= "security/fog0000000007.html">$x.headline$}</a><br>"

Any suggestions? Thanks again for your time, by the way, especially on a Weekend too!

Robert Moir
Sunday, January 13, 2002

Robert,

I'm sure Joel has the definitive answer on this, but it sounds to me like you're pasting the script in Normal View rather than HTML View. I work around this by making the page look pretty in Normal then switch to HTML to paste in the script(s).

Eric Chromick
Sunday, January 13, 2002

You might be missing some {'s.  In the example you pasted in above, one is missing from:

">$x.headline$}"</  should say ">{$x.headline$}"

My old eyes go bleary looking for stuff like that.

TK
Sunday, January 13, 2002

Eric,
Thanks, that helped. I think each of the three of us had a piece of the answer to the problem between us. There was a slight problem with the script even after I pasted it in using html mode, but it was a lot better that way.

In case anyone else is doing something similar, my sidebar for the index page looks like this:

New Security Articles

{$ foreach 3 x in (folder "security") sortDescendBy .filedDate $}

{$x.headline$}
{$setDateTimeFormat "English" "dd MMM, yyyy" "hh:mm"$}{$x.filedDate$}

{$next$}

New Windows Tips

{$ foreach 3 x in (folder "windows") sortDescendBy .filedDate $}

{$x.headline$}
{$setDateTimeFormat "English" "dd MMM, yyyy" "hh:mm"$}{$x.filedDate$}


{$next$}

Robert Moir
Sunday, January 13, 2002

My fault, I should have tested it before I posted it! :|

Joel Spolsky
Sunday, January 13, 2002

It would be nice to have a series of examples and scripts available to "cut and paste"...

A E Senior
Sunday, January 13, 2002

Terry Kearns is collecting a lot of scripts and tips on his CityDesk web site:

http://tk-jk.net/city/index.html

Darren Collins has another great site:

http://www.pool-room.com/CodeCraft/CityDesk/fog0000000006.html

Joel Spolsky
Sunday, January 13, 2002

You only get two levels.

So -- a variable in a body (2) evaluates
A script in a variable in a body (3) doesn't
A script in a variable in an HTML file (2) does.
A variable in a variable in an HTML file (2) does
A variable in a varaible in a body (3) doesn't.

It's sort of dumb. We have this stupid code I personally wrote which goes through the file, replaces all the CityScript once. Then it does this a second time.

What it should really do (and will do) is go through the file, replacing the CityScript, and then if it notices that it is pulling in even more CityScript, it should replace that recursively.

The reason we didn't it right the first time is that it creates a risk of an infinite loop, for example if your X variable is defined as {$.x$}. So we will have to have loop detection and avoidance.

Joel Spolsky
Monday, January 14, 2002

*  Recent Topics

*  Fog Creek Home