Fog Creek Software
Discussion Board




Knowledge Base
Documentation
Terry's Tips
Darren's Tips

Server side Includes

Here is an interesting situation...

I've adapted my CityDesk to pages to use server-side includes.  I use two, one for the main header at the top and one for the footer (they are .asp pages).

It works great.

However, I ran into an issue with the magic names.  In the header include I have an image (quite typical) like so:


  <IMG height="100" hspace="4" src="PTMFOG0000000011.jpg" width="800" useMap="#Map" border="0">


This works for any pages that are in the root folder that include this file.  However not for any pages resulting from a template in a subfolder.  I get a broken images.

I fixed this by prepending a / in front of the image file's magic name, such as:

  <IMG height="100" hspace="4" src="/PTMFOG0000000011.jpg" width="800" useMap="#Map" border="0">

Now all the pages in the root and subfolders work fine when published.

But when try to edit the pages in an editor, say DreamWeaver, I get a broken image link now.  It is still functional, but I can't get it where it works both in the editor and in the final publish at the same time.

This problem seem to be limited to files that are server-side includes.  And I cannot really figure out how to work around it.  Any ideas?

David Whatley
Saturday, February 23, 2002

Why, if you're using CityDesk, are you using Server Side Includes for simple things like headers and footers, when CityDesk is so good at it?

Simply create an article called "header" and another called "footer" and put the following code in the proper place:

{$foreach 1 x. in (filename "header") $}
{$x.body$}
{$next$}

You can substitute (filename "header") for (keyword_contains '(header)") if you think you'll ever create an article named "header." If you ever think you'll use the keyword header, then you can go for the "author" field and feel fairly positive you won't ever create an article with the author of "header."

This way you can edit the header in DreamWeaver and all the links to the images will work. It'll be less server load too - your server won't have to parse every article to get it to work, it'll just spit them out, CityDesk will do all the crunching for you.

You might have to work around some things like if you ever put a script like this:

{$foreach x in (all) $}

you'll have to make it

{$foreach x in (and (not filename "header) (not filename "footer") $}

or some such thing.

As someone who had a site that used Server Side Includes and switched them over to CityDesk, I can say that it works great unless you have something that has to execute server-side that you need brought into the page, like <!-- #exec virtual="timer.cgi" --> (sorry if my syntax is a bit wonky, I don't use SSI that much), but it doesn't sound like you do.

Mark W
Sunday, February 24, 2002

. . . or use variables. Works just as well.

Ryan
Sunday, February 24, 2002

Yeah, but you can't edit variables in DreamWeaver.

Mark W
Sunday, February 24, 2002

Yes, I realize I can use articles and/or variables to achieve the common header/footer.  However, both of these techniques give a pretty ugly editing experience.  During my page development, I want to see how all the elements work together visually while working.  DreamWeaver is kind enough to visualize the server-side includes WYSIWYG during editing.

But even if I abandoned SSI for this purpose, it points out a problem with the magic names.  A subtle problem, I think, but one that will crop up with any mildly complex work that touches on SSI.  And there are more reasons for them than just what I'm doing.

David Whatley
Monday, February 25, 2002

This problem is actually not related to CD's magic names.  It has to do with the difference between ABSOLUTE url's and RELATIVE url's.  Since you are using SSI's and including that header file, the server just plops the contents of your header file into the html file it was included in.  Since you don't know ahead of time all the different places that you are going to use the header file you MUST use an absolute URL to reference any images or links in the header file... something like "/images/foo.gif" or "http://www.myserver.com/images/foo.gif". 

If you use CityDesk's internal templating mechanism instead of the server side include mechanism, then at publish time CD can look at your site and see all the places where you are going to include the header file and adjust the relative url in each place.  (it might insert the header into a file at the root and use the url "images/foo.gif" and at the same time insert the header into a file deep down in the tree structure and use the url "../../images/foo.gif")

Anyway, if you want to use SSI's, then don't let the magic names confuse you.  Just don't use them.  Insert the absolute URL to the image file in there.

Michael H. Pryor
Tuesday, February 26, 2002

I concur with Michael. This is a problem with SSI & Dreamweaver whether you're using CityDesk or not.

Mark W
Tuesday, February 26, 2002

I followed the advice given which suggested creating an article called "header" and referring to it with a {$.foreach ... $} block.

So I created a new article, pasted the HTML for my header in there, and put the reference to it in the template I was building.

Upon preview, it was evident that the header file was included; however, all of the characters were interpreted, so instead of getting "<HTML>", I got <P>&lt;HTML&gt;

How come?

By the way, when I pasted the same HTML into a VARIABLE instead of an article, and referred to the variable, it worked fine. However, I find the variable editing window to be awkward, so I'd like to figure out the article-based approach

Brent Klassen
Thursday, April 11, 2002

I'm replying to my own query. Of course, when I copied the HTML snippet into the article, I did so in the "Normal View", instead of the "HTML View". Duh.

Having now copied the snippet into the "HTML View", it works fine.

Brent Klassen
Thursday, April 11, 2002

*  Recent Topics

*  Fog Creek Home