Fog Creek Software
Discussion Board




Knowledge Base
Documentation
Terry's Tips
Darren's Tips

Skipping an article in CityScript

A chunk of one of my pages:

<h3>Top story</h3>
      <P>{$foreach 1 x in (folder "Articles")$} </P>
      <P><A href="{$x.link$}">{$x.headline$}</A><BR>
      <FONT size=1>{$setDateTimeFormat "English" "dd MMM, yyyy" "hh:mm"$}{$x.filedDate$}</FONT>
      <BR>
      {$x.body$}</P>
      <P>{$x.extra2$}</P><table border="0" bgcolor="#99ffff">
  <tr>
    <td width="100%"><b>    {$x.sidebar$}</b></td>
  </tr>
</table>{$next$}
<hr>
<h3>Previous stories</h3>
      <P>{$foreach 10 x in (folder "FrontPageNews")$} </P>
      <P><A href="{$x.link$}">{$x.headline$}</A><BR><FONT
      size=1>{$setDateTimeFormat "English" "dd MMM, yyyy"
      "hh:mm"$}{$x.filedDate$}</FONT>
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      {$x.teaser$}<BR> {$x.extra2$}</P>
      <P>{$next$}     


The effect of this is to show the full text of the top story, and then just headlines and teaser info for stories 1-10.

What I'd really like, of course, is to show headlines and teaser info for stories 2-10, rather than repeating the headline for the first story.

I'm probably just missing some obvious CityScript feature here, right?

(If you want to see the page in action, it's at http://www.larkware.com )

Mike Gunderloy
Saturday, December 28, 2002

Oops...assume the same folder name for both foreach loops...

Mike Gunderloy
Saturday, December 28, 2002

the best way I can think of to do this would require you to change the first article in some way: put it in a different folder or add a keyword. This requires a little bit of maintenence, e.g., moving the article from the "FIRST ARTICLE" folder to the "OTHER ARTICLES" folder...

Joel Spolsky
Tuesday, December 31, 2002

Well, if you can't think of a better way, I'm pretty sure there isn't one :)

I tried the "separate folder" solution for a while - the problem is that external links then break when I move the article to the permanent folder. I've got a custom 404 page that takes care of that, but still, a nuisance.

Keywords, though, is an obvious solution that I should have thought of myself.

Meanwhile, you might add "generalized foreach" to the "vague and impossible to implement customer wishlist" section of your CityDesk 2 planning.

Mike Gunderloy
Wednesday, January 01, 2003

I you have a custom 404 page, you can make it 'active' (by adding client or server side scripts). Also, if you are allowed to redirect 404's you may be allowed create a redirection list as well. So you can redirect all first/articles to older/articles and control this by cityscript.

Adriaan van den Brand
Thursday, January 02, 2003

Yup, I already use my 404 scripting to fix things up. Poor solution, though; if you do a server-side redirect, then the bad links hang around out there and continue to cause extra work and confusion; if you do a client-side redirect, it takes extra time for the browser.

Mike Gunderloy
Thursday, January 02, 2003

For server side redirect: you can specify the return code so spiders etc. know that the page has moved. But it is still a poor work around for a limitation in cityscript.

Adriaan van den Brand
Thursday, January 02, 2003

You could maintain a variable which you keep set to (say) the filename of the first article, then use SSI conditionals to supress the unwanted summary as the page is served.

To make this technique more automatic, you could have an outer loop selecting only the first article, and an inner one selecting all 10. This will still only loop through all 10 articles once, but you can compare the two sets of loop variables in SSI to select a different format for the first article. Something like :

{$foreach 1 x in (folder "foo")$}
{$foreach 10 y in (folder "foo")$}
<!--#if expr=" '{$x.filename$}' = '{$y.filename$}' " -->
{$y.body$}
<!--#else -->
{$y.teaser$}
<!--#endif -->
{$ next $}
{$ next $}

The pre-SSI HTML could get rather long this way, but if you also use SSI to include the article body, only the one you want will get pulled in. This may involve creating a new template family, though.

Michael Wild
Thursday, January 02, 2003

Have you noticed that the foreach 10 doesn't seem to always only get you 10?

I am just putting together my site now, so the .filedate property on all the files is the same.  When I use code straight from the help file to get the 10 highest filedates, I actually get 12-16 files...

So I'd say don't count on getting explicitly the number of files that the foreach specifies.

John

John
Friday, January 17, 2003

*  Recent Topics

*  Fog Creek Home