Templating PoC
this document is ugly and deprecated!
- How does templating want to work?
- I think the best method would be to have html fragments and build an array of pieces to be assembled on output.
- each fragment should be built by the module (using a basic template engine?)
- each fragment should be encapsulated in its own div with a unique id (the module name) for easy styling
- each fragment should be valid xhtml
- each fragment should be style-less (all styles will be CSS)
- the entire fragments will be ordered and thrown into the final output based on their array order
- the final output will be wrapped in a basic shell with a few global variables (modifiable by modules)
- common components will be generated before final output (allowing variable modification before processing)
- variable replacement
- language support
src/ +--+- modules/ | +--- class-moduleName.php | +-+- moduleName/ | +-+- template/ | | +---- anyname.xml | | ----- anyname.css | +-+- language/ | ----- langCode.xml (en.xml, fr.xml, etc.)
first method could get messyit's junk.second allows for more flexibility with different templates.it's junk- third method keeps them self contained - has super flexibility - but has the source, tpl's and lang almost mixed.
- I like this one. It's a nice drop-in method for modules. Could in fact be used for updatability.. maybe even move the .php file into moduleName and also allow for other .php files if necessary.
main variables
these are all reserved for the Templates Class
- TITLE
- SCRIPTS
- CSSIMPORT
- PAGEID
- HEADER
- SITEMENU
- MODULEMENU
- MODULECONTENT
- FOOTER
using variables
anything in {} will be considered a variable.
example usage: myAction.xhtml
<p>this is my {Variable}!</p>
Template::setVariable('Variable', 'beer loving day');
<p>this is my beer loving day!</p>
Variables are Case Sensitive. You are free to use the global variables anywhere in your templates, however be warned that they will not work if you setVariable in your module.
Any unused {} elements will remain in the template. They will not be destroyed (so if you actually intend on using them, they'll be preserved) If you have leftovers that you need to get rid of, you must assign them as empty setVariable("myEmptyVariable", "");
loop blocks
example usage: myAction.xhtml
<ul>
<!-- block:myBlock -->
<li>{SomeVariable}</li>
<!-- endblock:myBlock -->
</ul>
How?
Template::useBlock('myBlock');
for ($i = 1; $i < 10; $i++)
{
Template::setVariable('SomeVariable', $i);
Template::releaseBlock();
}
Result:
<ul> <li>1</li> <li>2</li> <li>3</li> <li>4</li> <li>5</li> <li>6</li> <li>7</li> <li>8</li> <li>9</li> </ul>
setting CSS and JS files
Template::addCSS($filename); Template::addJS($filename);
where $filename is a filename found in the modules css and js directory.
set the title
Template::setTitle($string)
Sets the page title. Note the page title will also have a config variable (siteTitle) appended to it.
see also: Site Style, Site Style Users