Managing Content Fragments

by Darren Collins
Thursday, 4 July 2002

I like to include things like links to recommended books (like the one on the right) or lists of links to other sites (like the right-hand column on my Photography page) on the pages of my site. I started off writing these things (let's call them content fragments) in the Extras fields of articles, and using my templates to put them in an appropriate place on the final page.


After writing a few articles, I realised that there were some content fragments that I wanted to appear in several places on my site. Having the same stuff in two places leads to maintenance nightmares, so I copied the fragment from the first article into a variable, and then put a reference to that variable into the Extras fields of the two articles. Now anywhere I wanted my list of web-related books to appear, I could just type '{$.WebBooks$}' and CityDesk automatically inserted it. Sweet.

I came across a new book I wanted to add to my list, and I soon discovered that CityDesk variables are a pain in the butt to edit. You don't get a nice WYSIWYG editor, so you've got no idea of what your HTML code will look like. With the Variables window open, you can't right-click on articles in the CityDesk Main Window, so copying and pasting Magic Names becomes a repetitive click-fest of opening and closing the Variables window and its Edit window.

Variables are fine for short snippets of text or content fragments that almost never change (such as the 'Made With CityDesk' logo on the left), but not for maintaining regularly-updated, formatted content.

Dummy Articles

Then I hit upon the idea of putting my content fragments into dummy articles. This would give me the ability to edit them in both HTML View and Normal View, and I could include them in other pages with a snippet of CityScript like this:

{$foreach x in filename "Web Site Books"$}

I copied my book list to an article named 'Web Site Books', and stuck the code above into the WebBooks variable. I did something similar for all my other content fragments too. Now I can maintain them in a friendly editor, but still easily include them anywhere on my site via the variables.

A Few Extra Tips

  • I keep all my dummy articles together in a directory named 'Frag' (for 'fragments') for easy maintenance.
  • Every dummy article uses my 'Blank' template, so that only empty files get published to the /Frag directory on the server. This saves disk space, since these articles will never be viewed directly anyway.
  • I put '(NFP)' (short for Not For Publication) in the Keywords field of each of my dummy articles. All my scripts that list articles (as used on index pages) and recent additions (as used on the main page) exclude articles that have '(NFP)' in the Keywords, so that only real articles get listed.

Follow Up - CityDesk 2.0

With the introduction of CityDesk 2.0, content fragments are even easier to insert into articles. You just use the 'insert' statement in CityScript:

{$include "Web Site Books"$}

This simply includes the body of the article named "Web Site Books" into the current page. Simple!


Related Articles
- 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

Recommended Books

This site Copyright 1999-2005 Darren Collins.