Page 1 of 1

Sessions and DreamWeaver Templates

Posted: Thu Jul 17, 2003 2:03 pm
by Carl B
I'm running into a chicken & the egg problem here... I have a large number of pages (450 and growing) that I'm trying to keep consistant by using a combination of DreamWeaver Templates and PHP includes. The templated areas contain the includes and calls to custom functions to output standard headers & navgiation on every page, so that if for any reason the syntax for those function calls changes, I don't have to change it on a few hundred, or even a few dozen as a subset, pages.

Our latest development was to start adding session variables to handle information we wanted to have available on every page. The problem is that dreamweaver (MX) uses HTML comments to implement templates, so by the time we get to session_start(), there has been HTML output on the page. Is there any way around this, or am I going to have to abandon session handling and use cookies or something?

Re: Sessions and DreamWeaver Templates

Posted: Fri Jul 18, 2003 12:47 pm
by Net_Monkey
Carl B wrote:I'm running into a chicken & the egg problem here... I have a large number of pages (450 and growing) that I'm trying to keep consistant by using a combination of DreamWeaver Templates and PHP includes. The templated areas contain the includes and calls to custom functions to output standard headers & navgiation on every page, so that if for any reason the syntax for those function calls changes, I don't have to change it on a few hundred, or even a few dozen as a subset, pages.

Our latest development was to start adding session variables to handle information we wanted to have available on every page. The problem is that dreamweaver (MX) uses HTML comments to implement templates, so by the time we get to session_start(), there has been HTML output on the page. Is there any way around this, or am I going to have to abandon session handling and use cookies or something?
This is probably the best example of why presentation and application layers should be separated. You should, however, be able to continue with this system by create a simple SSI PHP script that executes the session start and place it at the very beginning of the file.

Dreamweaver doesn't put the first comment until after the HTML open tag (<HTML>). You can easily insert the SSI call right before the <HTML> and that should start the session before any HTML content is output.

Your best bet for the long run, though, would be to separate your application logic/layer from your presentation (HTML) layer into a single application file that includes libraries as necessary (I call these my control files -- all it has is include_once statements, function calls, and switch statements that determine what libraries get included and what functions run). Then you open a template and insert the generated content where you want (I designate my regions with simple markers, generate all my output, replace the markers with the matching generated content, then output the whole thing).

If you're able, this will make updates to the application a lot simpler and less problematic...

Regards,
Pete