CityDesk Template

13 February, 2002

So you're looking for CityDesk templates? Well here are some things that I'm using on this website. (Yeah, I know, there's nothing fancy here. I neither have the time nor the interest in getting fancy.)

My first tip is to put everything on your site into CityDesk. Files for download, pictures, whatever. Having it all in the CityDesk file just makes it easier.

Second: use variables liberally. Anytime I have something that gets repeated in more than one (ok, more than two) places, I put it in a variable. Because it is almost guaranteed that I'm going to want to change it at some point in the not-to-distant future. And finding all the places that the text occurs is a royal pain, not to mention the inconvenience of having to actually make the changes.

Third: use variables to set up page structures. You can use templates to do this for your articles, but I'm talking about my HTML pages (i.e. pages that aren't articles). I use HTML pages to provide summaries / lists of articles. My index.html looks like this:

{$.SiteHeader$}
Like the tag line says, this isn't
quite random. It's even almost 
organized, which is a little wierd
(those who know me can confirm this).
<TABLE width="100%">
<TBODY>
<TR vAlign=top>
<TD width="33%">
    {$.TOCTable$}
</TD>
<TD width="66%">
<TABLE width="100%" {$.TABLESTYLE$}>
  <TBODY>
  {$foreach 15 x in all
      SortDescendBy .fileddate $}
    <TR>
    <TD>
    <A href="{$x.link$}">{$x.headline$}</A>
    <FONT size=1>
      {$.DateFormat$}
      {$x.filedDate$}<BR>
      from the{$x.extra1$} department
    </FONT>
    <BLOCKQUOTE>
    <P>{$x.teaser$}</P>
    <P>{$x.extra2$}</P>
    </BLOCKQUOTE></TD></TR>
  </TBODY>
  {$next$}
</TABLE>
</TD></TR>
</TBODY></TABLE>

Two things worth noticing here: the use of the $x.extra2$ field, and the TOCTable variable. On pages that have a link to my discussion board, I fill in the extra2 field with a link to the relevant thread. Where there is no relevant thread, I can leave this field blank and nothing shows up in the article summary.

I use the variable TOCTable in all of my HTML pages to display a "table of contents" (TOC) on the left hand side of the page. By using this variable, I can change the TOC on every HTML page just by changing one variable. Here's a peek at TOCTable:

<table {$.TABLESTYLE$} >
  <tr><td width="33%">
    <A href="index.html">Front Page</A>
  </td></tr>
  <tr><td width="33%">
    <A href="rants.html">
      One Man's Opinion
    </A>
  </td></tr>
  etc...
</table>

Note that TOCTable in turn contains a another variable, which controls the style of the table (TABLESTYLE). I use this variable in all of the tables on the site. It is built into the template that all of the articles are published with, thus it controls the outline and other attributes of the tables on every page of the site.

In coming up with these techniques, I came across a couple of shortcomings in CityScript. First, you can't create a foreach loop inside a variable. I tried this, and maybe there's some way it is possible, but I kept getting errors. Secondly, there's nothing that works like a procedure call. I realize that all of this is asking a lot, but I think it would be pretty cool if the table in index.html and the other HTML pages could look like:

<TABLE width="100%">
<TBODY>
<TR vAlign=top>
<TD width="33%">{$.TOCTable$}</TD>
<TD width="66%">
<TABLE width="100%" {$.TABLESTYLE$}>
  <TBODY>
  {$ .my_foreach 15  $}
  </TBODY>
</TABLE>
</TD></TR>
</TBODY></TABLE>

Where my_foreach is a variable/procedure defined as follows. COUNT is some kind of parameter to this variable/procedure, using what I'm guessing Joel and the boys might provide for syntax:

{$foreach {$COUNT$} x in all
      SortDescendBy .fileddate $}
    <TR>
    <TD>
    <A href="{$x.link$}">{$x.headline$}</A>
    <FONT size=1>
      {$.DateFormat$}
      {$x.filedDate$}<BR>
      from the{$x.extra1$} department
    </FONT>
    <BLOCKQUOTE>
    <P>{$x.teaser$}</P>
    <P>{$x.extra2$}</P>
    </BLOCKQUOTE></TD></TR>
  {$next$}

Look how much this would shrink my main page! This makes incredibly easy to create "section pages" (i.e. my other HTML pages). I'm sure there are a dozen other uses for this sort of thing. The challenge is making sure that the use of parameterized variables can all be resolved at site generation time -- I don't want to force the creation of dynamic content.

On a final note, I don't actually use the Templates feature much. I have one template ("Simple", I'm linking to a copy of it rather than go through further pain massaging the CityScript so that the publication process doesn't freak out). All of my articles use this same template, although I'm trying to think of something interesting that I can do with this feature. Maybe I'll come up with something.