I came to a point where I realized that I need an intelligent solution for this problem.
In my framework, there are:
- Views (actually just HTML files with little PHP to output data)
- View Controllers (create views, do some logic)
So for every page like http://stackoverflow.com/questions/ask for example, I have an ViewController which is called by the framework. There's an RootViewController which creates an layout view. The layout view specifies headers and footers, and the main structure of the site. It has a contentView placeholder, for instance.
With this design I specify the HEAD part only once, and so the DOCTYPE, TITLE and all the other stuff is sticked to that layout view template.
Every View Controller which loads that RootViewController can set the title, append an CSS inclusion or Javascript inclusion (which is one of those fancy link rel tags in the HEAD), just by calling some methods on the RootViewController.
So far, that's actually pretty flexible, because if you don't specify anything, you get useful defaults and an reasonable HEAD with everything needed.
But I see these problems:
Can't I make life for the framework user more simple? The layout template must contain all this "garbage" that kills productivity. Why should a framework user even have to think about setting up a correct HEAD? It's always the exact same problem, needs the exact same syntax, the exact same inclusions of CSS and Javascript of the framework, etc. ...you get the point.
It would have to contain the exact corresponding placeholder variables to match the methods of the RootViewController.
So to solve this, I thought I could provide an fancy variable which can be inserted into any view template to output the HEAD block.
I just want to see what you think about this, and if my solution is just fine, or if I'm about to make a big design error here. And if so, what would be the alternatives?