Download the PHP package redcatphp/templix without Composer
On this page you can find all versions of the php package redcatphp/templix. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download redcatphp/templix
More information about redcatphp/templix
Files in redcatphp/templix
Package templix
Short Description Templix - HTML5 based Template Engine with Recursive Extends and CSS3 Selectors to work on DOM like with Jquery
License LGPL-3.0+ CC0-1.0
Homepage http://redcatphp.com/templix-template-engine
Informations about the package templix
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:
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.
Options
Dev
Paths
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.
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
"./" prefix - look in priority in same directory than the current template
"/" prefix - look in priority in at root of working directories in order they are defined
"//" prefix - look in priority for abosulte path
HTML5 Plugins
XHTML
The main differences between HTML5 and XML/XHTML syntax is that in XML syntax we have to close every elements, it support self closing but there is not implicit self closing unlike in HTML5. In XML there is no support for shortcut attributes, all attributes have to be composed by a key and a value. In XML we have also to convert all HTML named entities in their numeric entities equivalent. The doctype is also different but except these few variations we can switch from one to other very simply.
In Templix if you change html5 doctype declaration "" to "", the output syntax will be automaticaly changed to XHTML without any change to do in your templates !
The parser support the most flexible syntax than is HTML5 with some Templix addons pecificity like shortcut value but, by dint of DOM conversion to PHP object, the output can be changed in XML very easyly. According to W3C specification, the following elements are implicitly self-closed:
- area
- base
- br
- col
- command
- embed
- hr
- img
- input
- keygen
- link
- meta
- param
- script
- source
- style
- track
-
wbr
You can found how the self-closed implemation is done by taking a look at "RedCat\Templix\MarkupHtml5" namespace in "redcat/php/RedCat/Templix/MarkupHtml5" directory.
Markup Object Methods
Markups object will be called node in following documtentation.
closest
The closest method is used to find through the node's ancestors the first matching element which are closest from the current node.
searchNode
The searchNode method is used to find the index of a node in the children nodes of the node if it's there. The second parameter can be used to start search from an index.
match
The match method is used to determine if a node is corresponding to a selector.
find
The find method is used to find matching selector in all enclosed nodes. The second parameter can be used to specify an index of result.
If you specify an index to "true" the result will not be an array of nodes but a nodes iterator object which you'll can traverse like an array and using a foreach but which can also be used to call sub methods like to a regular node.
children
The children method is used to find matching selector in first sub-level of nodes. Like in find method, the second parameter can be used to specify an index of result.
If you specify an index to "true" the result will not be an array of nodes but a nodes iterator object which you'll can traverse like an array and using a foreach but which can also be used to call sub methods like to a regular node.
merge
The merge method will merge the parameter node passed to method with children nodes of the node.
If an equivalent node allready exists the node will not be added to avoid duplication. If the parameter is scalar value it will be converted to a tree of nodes.
If the element didn't allready exists, it will be added after existing ones.
premerge
The premerge method will merge the parameter node passed to method with children nodes of the node.
If an equivalent node allready exists the node will not be added to avoid duplication. If the parameter is scalar value it will be converted to a tree of nodes.
Contrary to merge if the element didn't allready exists, it will be added before and not after existing ones.
submerge
The submerge method will merge children nodes of the parameter node passed to method with children nodes of the node.
Like in merge, if an equivalent node allready exists the node will not be added to avoid duplication. If the parameter is scalar value it will be converted to a tree of nodes.
isSameNode
The isSameNode method will compare the node to the node parameter based on children nodes, attributes and class name and will return a boolean. It's an equivalence comparison and not a strict comparison based on object memory reference.
getAttributes
The getAttributes method allow you to get the attributes as an associative array.
hasAttribute
The hasAttribute method allow you to know if an attribute is defined.
getElementsByTagName
The getElementsByTagName method is like the regular javascript method, it get the elements by tag name recursively starting with the calling node itself.
write
The write method will clean the inner head, inner foot and children nodes before appending parameter, head and foot will be conserved. If the parameter is scalar value it will be converted to a tree of node.
append
The append method will add the parameter to children nodes after the existing ones. If the parameter is scalar value it will be converted to a tree of node.
prepend
The append method will add the parameter to children nodes before the existing ones. If the parameter is scalar value it will be converted to a tree of node.
each
The each method receive a callback as argument. It will apply on the node or iterate through an iterator node and apply on each node.
replaceWith
The replaceWith method allow you to replace a node with an other in parent's children nodes. If the parameter is scalar value it will be converted to a tree of node.
remove
The remove method will remove the node from parent's children nodes.
applyFile
The applyFile method will read the filename, usually a ".tpl" file, which contain applicators markup to modify the node like the first level of markups do in extend.
before
The before method will add the parameter just before the node in parent's children nodes. If the parameter is scalar value it will be converted to a tree of node.
after
The after method will add the parameter just after the node in parent's children nodes. If the parameter is scalar value it will be converted to a tree of node.
getIndex
The getIndex method return the index of the node in parent's children nodes.
getInnerMarkups
The getInnerMarkups method return the string version of inner children nodes.
getInner
The getInner method return the string version of inner head, then inner children nodes, and finaly inner foot.
__toString
The __toString method return the whole node and all enclosed node as a string. This magic method is returned when you try to cast the node as string.
clear
The clear method erase head, inner head, children nodes, inner foot, foot, previous sibling, next sibling, detach itself from the next and previous flow and set hiddenWrap to hide markup opener and closer output.
clearInner
The clearInner method erase inner head, children nodes and inner foot.
head
The head method unshift a raw content or source code to the head of the node, before opening markup. A second parameter can be used to specify a splice index. If the splice index is true the raw content will be pushed instead of unshifted.
foot
The foot method push a raw content or source code to the foot of the node, after closing markup. A second parameter can be used to specify a splice index. If the splice index is true the raw content will be unshifted instead of pushed.
innerHead
The innerHead method unshift a raw content or source code to the inner head of the node, after opening markup. A second parameter can be used to specify a splice index. If the splice index is true the raw content will be pushed instead of unshifted.
innerFoot
The innerFoot method push a raw content or source code to the inner foot of the node, before closing markup. A second parameter can be used to specify a splice index. If the splice index is true the raw content will be unshifted instead of pushed.
attr
The attr method is a getter or setter for accessing attributes. It will be a getter with one argument and a setter with two arguments.
tmpAttr
The attr method is a getter or setter for accessing temporary attributes.
Because of extend or apply, the DOM can be re-compiled to string and re-parsed. In this processus, all unvisible meta-data you can add to your object, like with the data method, will be wiped. So, there is a convention for passing meta-data in a node with the urlencoded key-value pairs "tmp-attr" attribute. This attribute is a visible attribute working with not "hiddenWrap" nodes (visible opening and closing markup), but they will be removed automaticaly just before the end of global compilation.
It will be a getter with one argument and a setter with two arguments.
removeAttr
The removeAttr method remove an attribute from opening markup of node.
remapAttr
The remapAttr method is used for add a key to a shortcut attribute or shortcut value according to its order in attributes. The first argument specify the key to add and the second argument the index of shortcut, starting with zero. The index is zero by default.
data
The data method is a getter or setter for accessing meta-data unvisible attributes.
Because of extend or apply, the DOM can be re-compiled to string and re-parsed. In this processus, all unvisible meta-data you can add to your object, like with the data method, will be wiped. To work around this behavior use tmpAttr instead of data.
It will be a getter with one argument and a setter with two arguments.
css
The css method is a getter or setter for accessing css properties of style attribute. It will be a getter with one argument and a setter with two arguments.
removeClass
The removeClass method allow you to work on class attribute by removing class in a regular way without to have to work on class string attribute directly.
addClass
The addClass method allow you to work on class attribute by adding class in a regular way without to have to work on class string attribute directly and avoiding duplication.
wrap
The wrap method allow you to enclose a node or a tree of nodes in a node. If you pass it a tree of node it will use the first top encloser node as the wrapper. If the parameter is scalar value it will be converted to a tree of node.
unwrap
The unwrap method allow you to remove a wrapper. You can also use a selector to specify the closest matching wrapper you want to remove from ancestors. By default, it will be the closest encloser (selector "*").
createChild
The createChild method will create a node in children node from scalar content.
recursive
The recursive method allow you to execute a callback on each node recursively and also break the recursion from callback context. The callback will be executed from deepers elements to top.
arecursive
The recursive method allow you to execute a callback on each node recursively and also break the recursion from callback context. Contrary to recursive the callback will be executed from top elements to deepers.
getIterator magic
The getIterator magic method allow you to work with children nodes like if they were array of nodes and iterate over them with a foreach loop.
offsetSet magic
The offsetSet magic method allow you to work with children nodes like if they were an array of nodes and set a child node like an offset. If the parameter is scalar value it will be converted to a tree of node.
This is equivalent to:
offsetGet magic
The offsetGet magic method allow you to work with children nodes like if they were an array of nodes and get a child node like an offset.
This is equivalent to:
offsetExists magic
The offsetGet magic method allow you check if a child node exists.
This is equivalent to:
offsetUnset magic
The offsetGet magic method allow you to remove a child node.
This is equivalent to:
__get magic
The __get magic method allow you to directly get an attribute.
This is equivalent to:
set magic
The __set magic method allow you to directly set an attribute.
This is equivalent to:
__isset magic
The __isset magic method allow you to directly check if node has an attribute.
This is equivalent to:
__unset magic
The __unset magic method allow you to directly remove an attribute.
This is equivalent to:
__invoke magic
The __invoke magic method allow you to directly work with a collection iterator.
This is equivalent to:
Native Plugins
Attribute Plugins
Some attributes trigger special behaviors injections and then becomes unvisible. The way to implements an attribute trigger function to a markup is to implements a method which will be named with load prefix followed by upper case first character of attribute name. The hyphen "-" in attribute name will be replaced by underscore "_" in method name. If you want to capture all attributes which is prefixed by a name followed by hyphen "-", like "data-" for example, you can implements "loadAttr" method ending with underscore "_". Let's take some example:
Universal Attribute Plugins:
vars
The vars attribute is used to wrap inner content with sprintf interpolation function.
cacheSync
The cacheSync attribute is used with a sync path. The content of the markup will be cached and regenered only if its modified time is older than the modified time of the sync path.
To update the cache
For configure the path of sync files:
cacheStatic
The cacheStatic attribute is used as shortcut attribute to cache indefinitely the content of the markup.
Markup Plugins:
after
Markup usage of after method. The after markup have to be used at first level inside
append
Markup usage of append method. The append markup have to be used at first level inside
apply
Markup usage of applyFile method. It's the reversed process of
The {{this:property}} special syntax, specific to apply, allow you to access attributes of current targeted node tu build your apply in a more flexible and dynamic way. Tpl file:
The {{compile:callback()}} special syntax, specific to apply, allow you to pre-compile some portions of code using attributes of current targeted node tu build a faster and more consistent compiled template. Tpl file:
attr
Markup usage of attr method. The attr markup have to be used at first level inside
attrappend
The attrappend markup have to be used at first level inside
attrprepend
The attrprepend markup have to be used at first level inside
before
Markup usage of before method. The before markup have to be used at first level inside
case
Case is a basic php syntax structural element.
code
The code markup allow you to put unparsed code like in