Cotonti / Open Source PHP Content Management FrameworkContent Management Framework

Forums / Cotonti / Core Labs / Archive / A way to control metas and title from anywhere

Without changing normal script flow

Trustmaster
#1 2009-10-19 03:51
The original task is filling metas and title with most relevant information as of #374. It is possible in some parts like pages, lists and forums, but won't work for standalone plugins, because header is already sent to output by the moment plugin is executed.

Previously we knew 2 possible solutions of the problem:
  1. Get the output buffer contents, replace HTML metas and title using regular expressions, drop the buffer and send the modified value again. Which would work, but is rubbish.
  2. Change script execution flow from header/body/footer to body/header/footer. Which is possible, but would affect some plugins which rely on existing flow.

I've recently come up to another solution:
  1. Use separate XTemplate variables in each part instead of just $t, e.g. $header, $body, $footer.
  2. For compatibility and less changes in core, make $t a reference to current template object.
  3. Call parse(MAIN) and out(MAIN) on those templates after all (i.e. in footer) in order they appear in code.
Pros: this way you can modify tags from main blocks of templates in any part of the script, be it header, body or footer. Including tags used for metas and title in header of course. Without changing normal flow of the script itself!
Cons: it will consume more RAM than it does now, because all the templates will stay in memory until released at the end. And probably some other things I haven't considered.

What do you think?
May the Source be with you!