CityDesk: Using the "if" statement

15 March, 2002

Ahhh, my most prized feature request has been granted!! Thanks Joel & Crew!

To get an idea of why CityScript's new if-statement is so great, consider the following problem. If you look around at the pages on my site, you'll notice that a sidebar appears on the right side of most articles. I use this for, well, sidebar-ish kind of stuff. But only when I feel like it. And a few times, there, I felt like I was forcing it. I had only been using one template for all of the pages on this site: "Simple". But I had to create another template "NoSidebar" for those times that I didn't want to put anything into the sidebar.

With the advent of the if-statement in CityScript, I can delete my NoSidebar template, and just use the Simple template for all of my articles again. The if statement allows me to test whether a variable (in this case .sidebar) is blank or not. So the part of my template that generates the sidebar looks like:

<td width="30%" valign="top">
  {$ if nonblank .sidebar $}
    <table border="2">
      <tr><td>
        {$ .sidebar $}
      </font></td></tr>
    </table>
  {$ endif $}
</td>

There are a couple of other spots that I'd like to use this feature as well. I'm going to try some stuff and I'll let you know how it works!