Handy Variables

by Darren Collins
Sunday, 7 December 2003

Here are some handy variables I use in my CityDesk sites. Feel free to copy and paste them into your own sites.

Boxes

I defined three variables to create nicely formatted boxes, as explained in my Boxed Content article. That Related Articles box you see on the right side of this page was made using these variables.

box_start:

<table cellSpacing=0 cellPadding=3 width="100%" border=1>
<tbody>
<tr>
<td class=header>

box_mid:

</td></tr><tr><td class=content>

box_end:

</td></tr></tbody></table>

To create boxes in your articles, simply insert the variables like this:

{$.box_start$}Box Heading{$.box_mid$}Box content goes here.{$.box_end$}

Latest Articles

I created a variable named 'latest_articles' to display the 5 most recent articles in the current directory. The CityScript looks like this:

{$setDateTimeFormat "*" "d-M-yyyy" "hh:mm"$}
{$ foreach 5 x in (and (thisFolder) (not (thisArticle))
  (not keyword_contains "(NFP)")) SortDescendBy .filedDate $}
  <p>{$.filedDate$}: <a href="{$x.link$}">{$x.headline$}</a>
  {$.em$}{$x.teaser$}</p>
{$ else $}
{$ before $}
  {$.box_start$}Latest Articles{$.box_mid$}
{$ after $}
  {$.box_end$}
{$ next $}

If there aren't any articles in the current directory, it won't create the box.

Related Articles

I've got another variable named 'article_links' that goes into the sidebar (the right-hand column) of my templates, so that it appears on every page in the site:

{$ foreach x in (and (thisFolder)
  (not (thisArticle)) (not keyword_contains "(NFP)")) $}
  - <a href="{$x.link$}">{$x.headline$}</a>
{$ between $}
  <br>
{$ else $}
{$ before $}
  {$.box_start$}Related Articles{$.box_mid$}
{$ after $}
  {$.box_end$}
{$ next $}

It creates a box containing links to all the other articles in the current directory. If there are no other articles, it won't create the box. It won't include the current article in the list.

Note that no sort order is defined in the variable - so the articles will be listed in the order they're arranged in the current folder. This is handy. You can reorder the articles in each folder into a logical sequence so that your article list reads nicely.

Amazon Book Links

I often link to books at Amazon.com, and receive a small commission through their associate program. To make the linking easier, I use the following variables. To use them on your site, just change my affiliate code ('thecodecraftnews') to your own.

book_start:

<iframe marginwidth="0" marginheight="0" src="http://rcm.amazon.com/e/cm?o=1&l=as1&f=ifr&t=thecodecraftnews&p=8&asins=

book_end:

&IS2=1&lt1=_blank" frameborder="0" width="120" scrolling="no" height="240"><map name="boxmap-p8" id="boxmap-p8"><area shape="rect" coords="14, 200, 103, 207" href="http://rcm.amazon.com/e/cm/privacy-policy.html?o=1" /><area coords="0,0,10000,10000" href="http://www.amazon.com/exec/obidos/redirect-home/thecodecraftnews" /></map><img src="http://rcm-images.amazon.com/images/G/01/rcm/120x240.gif" width="120" height="240" border="0" usemap="#boxmap-p8" alt="Shop at Amazon.com" /></iframe>

To insert a book link, all you need to know is the book's ISBN (which you can look up at the Amazon.com web site). You then write something like this:

{$.book_start$}076454862X{$.book_end$}

The above code generates this link:

Other Affiliate Links

I'm a member of other affiliate programs, such as Google's Adsense (the blue ads you see on the right side of this page). Similar to the Amazon links above, I put the code for these affiliate links into variables to make them easier to sprinkle around my web sites. It also means I only have to change the code in one place if the affiliate links change.

Web Site Colours

All the colour values for my web site are stored in variables, which are then picked up in the CSS file and HTML templates. All these variables have names starting with a 'c', so that they're sorted together in the Variables window. I've also got all the colour variables listed on my Design Test Page to help see what's going on when I mess with the site design.

 


Related Articles
Index
- Handy Variables
- Design Test Page
- CityDesk Beta 2.0.1 First Impressions
- Boxed Content
- Managing Content Fragments
- CityDesk Short Tips
- Template Mockups
- Creating A Main Page
- Index Pages
- Using Folders
- Committee Intranet Site
- Migrating to CityDesk
- CityDesk First Impressions
- CityDesk Links

This site Copyright 1999-2005 Darren Collins.