Fog Creek Software
Discussion Board




Knowledge Base
Documentation
Terry's Tips
Darren's Tips

Tip: Using variables in Keywords field

I wanted to recreate an effect that I often see on Movable Type websites: hyperlink reference in the article itself to the categories to which it's assigned. See http://www.steptwo.com.au/columntwo/ for a representative example of this.

I was pleasantly surprised to find that variables work in the Keywords field. I created a variable to each of my article categories with the following syntax:

<a href="PTMFOG0000000042">Family</a>

for example, for the variable "{$ .catFamily $}. You can separate multiple categories in the Keywords field with the separator of your choice.

I now "categorize" an article by inserting my variable names. In my article detail template I have the following line:

<p>Categories: {$. keywords $}</p>

which pulls in the hyperlinks like a charm. It's now easy to jump from an article to any one of its multiple category indexes. It's clearly not as automated as with Movable Type or other packages of their ilk, but hey, not that difficult, either. And not too bad on the data entry side, either, because the HTML neophytes can choose the categories from the drop-down list.

Incidentally, you can still use the variable names in other scripts to build indexes, but you'll need to leave out the brackets, lest CD attempt to parse the variables (in which case you get nothing). In other words, (keyword_contains "catFamily") works fine, but (keyword_contains "{$ .catFamily $") does not.

Scott McDonald
Friday, February 20, 2004

Very good idea, Scott!

Would one loose any functionality by using another field, say Extra1 or Extra2, instead of Keywords?

You would then be able to print out the categories on the web page (Categories: {$. extra1 $}), yet still use the Keywords field for other things like building custom indexes.

Paul iliano
Friday, February 20, 2004

Well, I'm using the script  (keyword_contains "keyword"), and as far as I know there is no equivalent for the other fields under the Extras tab (would be a nice enhancement, though!). And again, you can still easily build indexes from the keyword field, even if your keywords are variable names.

Scott McDonald
Friday, February 20, 2004

*  Recent Topics

*  Fog Creek Home