Templix
HTML5 based Template Engine with Recursive Extends and CSS3 Selectors to work on DOM like with Jquery
Install / Use
/learn @redcatphp/TemplixREADME
No longer actively maintained. I work now with NodeJS and I recommand you to take a look at ReactJS, Next.JS and EJS
Templix
Templix is a powerfull markup syntax based template engine.
Features
- recursive extend
- CSS3 Selectors (jQuery/sizzle like) to work on DOM at compilation time
- PHP compliant
- onCompile binder
- PHP short-open-tag syntax support even if not enable in php.ini
- PHP syntax elements ported to HTML5
- HTML5/XML syntax
- extended Templix syntax
- As fast as simple include when compiled
- Possibility to build your own markup based logic language
- Markup Object Methods- closest
- searchNode
- match
- find
- children
- merge
- premerge
- submerge
- isSameNode
- getAttributes
- hasAttribute
- getElementsByTagName
- write
- append
- prepend
- each
- replaceWith
- remove
- applyFile
- before
- after
- getIndex
- getInnerMarkups
- getInner
- __toString
- clear
- clearInner
- head
- foot
- innerHead
- innerFoot
- attr
- tmpAttr
- removeAttr
- remapAttr
- data
- css
- removeClass
- addClass
- wrap
- unwrap
- createChild
- recursive
- arecursive
- getIterator magic
- offsetGet magic
- offsetSet magic
- offsetUnset magic
- offsetExists magic
- __get magic
- __set magic
- __isset magic
- __unset magic
- __invoke magic
- Attribute Plugins- vars
- cacheSync
- cacheStatic
- Markup Plugins- after
- append
- apply
- attr
- attrappend
- attrprepend
- before
- case
- code
- css
- else
- elseif
- end
- eval
- extend
- for
- foreach
- if
- img
- include
- incorpore
- js
- link
- merge
- premerge
- submerge
- noparse
- pre
- prepend
- remove
- replace
- return
- script
- switch
- t
- var
- vars
- write
Templix syntax
The Templix syntax is based on diple sign < and >, so if you want to use them for other purpose than opening or closing a markup declaration, you have to use their html entites equivalent which are > and <.
The templix syntax is based on PHP and HTML5/XML, but like HTML5 add the shortcut attribute to XML, Templix add the shortcut value to HTML5:
<markup "my shortcut value" />
The markup between comment <!-- --> will not be parsed excepting the PHP.
onCompile binder
You can bind to templix some callback to trigger when the document is almost compiled and all its DOM is accessible.
$templix->onCompile(function($templix){
$templix->find('footer a')->addClass('footer-link');
});
Options
Dev
// re-compile each time
// add indentation and line feed for code readability
$templix->setDevTemplate(true); //default true
// add time suffix parameter to local css links to avoid browser caching
$templix->setDevCss(true); //default true
// add time suffix parameter to local js scripts avoid browser caching
$templix->setDevJs(true); //default true
// add time suffix parameter to local images to avoid browser caching
$templix->setDevImg(true); //default false
// add clean callback when switch from prod to dev
$templix->setCleanCallback(function(){
});
Paths
//set compile directory
$templix->setDirCompile('.tmp/templix/compile/'); //by default
//set cache directory
$templix->setDirCache('.tmp/templix/cache/'); //by default
//add mtime directory registry to use when you use "cacheSync" attribute
$templix->setDirSync('.tmp/sync/'); //by default
//set current working directories in order you want templix look for
$templix->setDirCwd(['template/','redcat/template/']); //by default
//add directories to stack of current working directories
$templix->addDirCwd(['template/','redcat/template/',]);
//the template file to display on call of $templix->display();
$templix->setPath($file);
Paths to Plugins
Paths to plugins are based on class namespace and eventually, autoloading. Each class plugin name end with the upper case of first charater of markup and start with prefix which can be a namespace (ending with \\) or simple prefix.
$prefixDefault = Templix::getPluginPrefixDefault();
// Templix\\MarkupX\\ , Templix\\MarkupHtml5\\ , Templix\\
$templix->setPluginPrefix($prefixDefault); //by default
$templix->addPluginPrefix($prefix,$prepend=true); //equivalent to prependPluginPrefix
$templix->appendPluginPrefix($prefix);
$templix->prependPluginPrefix($prefix);
Path relativity
The following rules are valable when you use directly PHP API display or setPath as same as you use markups include, extend, incorpore or attribute applyFile.
no prefix - look in each working directories of template and each parent templates
<include "my-template.tml">
"./" prefix - look in priority in same directory than the current template
<include "./my-template.tml">
"/" prefix - look in priority in at root of working directories in order the
