Fog Creek Software
Discussion Board

Knowledge Base
Terry's Tips
Darren's Tips

Inheritance in templates

Is there some way of building hierarchies of templates.  As I build my template files.  I can see that quite often I'm taking a file making a few changes to create a new template file.  Not a big deal but I can see where having to make changes to the common elements among the templates could lead to inconsistenices among the files.  For instance if I have the same horizontal top level menu going across the top of every page and I have 7 or 8 templates in my site that's 7 or 8 places that I need to change every time I maje a change to the menu (or color or size of a tabel or whatever else).  One way I've seen of solving a similar problem in the past was in Delphi where we implemented form inhertance.  Does this make sense or is it too goofy?


Ben Riga
Monday, February 4, 2002


This has nothing to do with inheritance, but I've turned my  horizontal navbar variable so I only have to mess with it in one place.

There's an example here:

Hope this helps with your navbar, at least.


Eric Chromick
Monday, February 4, 2002

I'm getting an "error 404" from this link.

I've been thinking about this as well. Let's say I have a template with a navbar that has 6 tabs. I'll need six versions of the navbar (one with each tab in the forefront). And let's say I do an style "extra links underneath the tab." So each of these six will now have several possible sub sections, all new templates.

A possible workaround is to create an article for each navbar and pull it in when you need it:

{$foreach x in (keyword_contains "navbar1")$}

Another is to create a global variable "navbar1" and call it into your code {$.navbar1$} whenever you need it.

While this allows you to maintain a central repository of templates, having to add code into each article body sort of defeats the purpose of templates & the ease of use of CityDesk.

I'm certain the Fog Creek folks will find an elegant solution.

Mark W
Monday, February 4, 2002

Sorry for the confusion.

The correct link is

There was a "." hiding in the other one.


Eric Chromick
Monday, February 4, 2002

I'd like to have the ability to define site-wide variables, and then override those variables on a per-folder or per-article basis. So, your template could contain a variable {$.navbar$}, which you override for each folder. Or you could override an image in the template, so that each section of your site has a different 'logo'.

I think this, combined with the other enhancements Joel has slated for SP1 (e.g. deeper variable expansion), would give us enough tools to solve the "duplicated code between templates problem".

Darren Collins
Monday, February 4, 2002

What you're describing is similar to the inheretance that Frontier has. I forget the exact progression but it went from something like gobal variable to site variable to folder, or v.v.

My current workaround is to code the navbar in the template as {$.extra1$} and then extra1 will link to the global variable, i.e. {$.navbar_products$}.

Since the navbar is always variations on the same image, I can keep a single imagemap as a global variable somewhere in the template {$.navbar_imagemap$}. While I guess this could easily exist in the template (since there's only one) I've coded it as a global variable to allow for expansion in the future.

Mark W
Monday, February 4, 2002

*  Recent Topics

*  Fog Creek Home