Have head in each template or have reusable function?

I assume by popups you mean javascript generated ones, so that would be done using Javascript to create the content dynamically, so it will still work with JS off.

Pop-Ups: target=_blank, or CSS overlays (usually hidden by JS).

But I was asking how would you deal with the inside/outside/popup wrappers.
How/where would your conditions be set?

I don’t know what you mean by ‘inside/outside/popup wrappers’. Or in fact what conditions you are referring to!

Let me rephrase.

When you have a website more complicated than a 3 page info site,

  • You have templates/designs for your landing pages, before your users login to the site (outside wrappers).
  • You also have a different template/design after users login to the site (inside wrappers).
  • You also have popup pages, or simpler pages like the terms and conditions, where your design is different from the rest of the site. (popup wrappers)

If your always including the same master template (in your system), how do you display one or another template/design (depending if the user is logged in, or the request url). Where do you have the logic block for all that?

Right, well I described pretty much all of that above! Different sections in the template can be switched on or off by the View class, based on data passed to it by the controller, or data in the models.

That’s kinda how my sites have worked up until now, instead the header and footer have been in separate template files, which is why I wanted to change it as it was becoming too complicated.

Parts of those templates however have blocks in them, like your <!–<SLAVE> –> block stormrider, that load in additional templates based on conditions. So for example, I have a block for a login area in my header template like LOGIN_PANEL, with logged in and logged out template files, with one of them loading based on a condition in my script. If I remove LOGIN_PANEL from template, the condition does not execute. Equally I could put the LOGIN_PANEL in my footer and it would still execute.

I need to be careful how many template files I have though, as it could become equally confusing and harder to track if files are not well organised and easy to follow for designers to make changes.

What if your logged in sections are spread over different areas of the header/footer? ie, they don’t meet the ‘panel’ model where you can just load in another block for it?

Sorry stormrider, I’m not sure what you mean. It’s the way I’m doing it at the moment and I’m not that keen on it anyway, as it’s too rigid and has no scalability at all. Here’s an example of a header I use at the moment:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta name="robots" content="__PAGE_INDEXING__" />
<meta name="description" content="__PAGE_DESCRIPTION__" />
<link rel="stylesheet" type="text/css" href="/css/styles.css" />

<script type="text/javascript" src="/third-party/jquery/jquery-1.3.2.min.js"></script>


<div id="pageHolder">

	<div id="customLinks">


The application builds up elements for these TAGS using variables (i.e. $this->top_content .= ‘<div>Menu</div>’). Once all the elements and content are ready for outputting (in this case HTML), the view model loads the relevant header and footer then I replace the TAGS with the relevant variable. I have a script which catches any unused tags and removes them just before HTML is echoed.

For a start, the tags make it harder for the designer to know where the elements are coming from. Maybe I’d have all the elements on the page for logged in and logged out, with some form of IF condition label the view model can control based on passed data. So maybe:

<div id="customLinks">
	<!-- IF: LOGIN -->
	<div id="loggedIn">
	<!-- /IF: LOGIN -->
	<!-- IF: LOGOUT -->
	<div id="loggedOut">
	<!-- /IF: LOGOUT -->

Found a good template engine called PHP XTemplate (http://www.phpxtemplate.org/HomePage) which deals with templates in a way I like. Small, keeps PHP out of code yet allows content to be hidden or displayed based on passed data. You also mentioned DRY before, which I haven’t really looked at and only came across it recently. I agree with the basic outline, need to read more about it.

Yup, my own templating system is based very heavily on X Template. I like the way they do blocks, without using words like ‘if’ or loops in the template. I am very fussy about white space and indentation though so I rebuilt XTpl in a way that keeps the white space intact.

My point above was… you currently have a LOGIN_PANEL tag, but what if your login thing doesn’t conform to that? What if you want to put content in multiple different places in the template when logged in? It assumes that all the HTML relating to being logged in will be in that one place, when it might not be.

In my example, the LOGIN_PANEL could be the login form (email address and password) or a ‘You are logged in as…’ block if you’re already logged in. I simply create additional tags using a different label in my template if I have other elements that are based on being logged in. If I decide I don’t want the login panel on a particular page, I delete the variable before the view model runs.

To extend that example, I may have another tag in my footer called LOGIN_DETAILS_PANEL, which display the user’s details when they are logged in; nothing when they are not.

The view model differentiates between template blocks and content, in that it loads the template blocks into the header first, attaches it to the body and footer (which have both done the same thing), then the content is applied to all.

That probably doesn’t answer your question stormrider. Maybe it would help if I put together an idea of what I’d like to do, may take a bit of time. The more I think about my current method, the more flaws I can identify :slight_smile:

Don’t worry, I see what you mean!