Download the PHP package codelake/template-flow without Composer
On this page you can find all versions of the php package codelake/template-flow. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download codelake/template-flow
More information about codelake/template-flow
Files in codelake/template-flow
Package template-flow
Short Description A simple and extendable templating engine.
License Unlicense
Informations about the package template-flow
TemplateFlow
TemplateFlow is a simple and extendable templating engine with a focus on E-Mail and HTML templating. Therefore, TemplateFlow may not work as expected if you want to output plain text which contains HTML special characters like . It provides an easy way to define and placeholders in a template and process them via pipes.
Template
In TemplateFlow a simple template can be defined as follows . Rendering that template with the desired data can be achieved as follows:
Pipes
Replacing placeholders with values is already nice to have but not really powerful. Therefore, TemplateFlow provides pipes. Pipes allow you to specify how a given placeholder value should be mutated before it is displayed. TemplateFlow already comes with a lot of predefined pipes. A complete list of the predefined pipes can be found at Predefined Pipes
There are also parameterized pipes - like shorten
-
which take a parameter. A parameter may be passed to a pipe
in parenthesis.
Some pipes also require more than one parameter.
To distinct multiple parameters, the pipe operator (|
) is used.
Adding Pipes
Pipes are just functions in a . Therefore, if you want to add your own pipes to TemplateFlow, you just have to create a new with the desired pipes as static methods on it.
It is recommended to use snake_case with lower case characters only, to guarantee easy to read pipes and prevent errors due to typos.
NOTE Since PHP is case insensitive in regard to function names, the use of camelCase and PascalCase are discouraged.
NOTE TemplateFlow will always try to execute discovered pipes (methods) in a static context. So, declaring a pipe as a normal method will lead to an exception.
Removing Pipes
In case you want to unregister/remove pipes, you can easily unregister the corresponding class. This will prevent TemplateFlow from creating new s with the class' methods. Existing s will still work as they already loaded the methods.
Predefined Pipes
In order to use predefined pipes, you first have to add it to the engine.
capitalize
Mutates the first character of a string to upper case.
link
Creates a link (anchor tag) with the specified address.
usage - for web links
usage - for mailto links
lower
Transforms all characters in a string to lower case.
raw
Returns a RawOutput
instance, so the pipeline result will not be escaped.
NOTE This pipe has to be the last one in the chain. Otherwise the output will be escaped as usual.
shorten
Cuts off the remaining characters of the pipeline string after the n-th character.
trim
Removes all whitespace characters from the left and right side of a string.
trim_left
Removes all whitespace characters from the left side of a string.
trim_right
Removes all whitespace characters from the right side of a string.
upper
Transforms all characters in a string to upper case.