Templates
Basic Hello World in Tina4
Templates in Tina4 are written in Twig. Tina4 exposes some common globals into the twig template so please make note of these, if you are worried about security use the following env config to remove them
TINA4_TWIG_GLOBALS=false
The globals map as follows:
|$_SESSION|session|
|$_REQUEST|request|
|$_COOKIE|cookie|
|$_SERVER|server|
We store templates in the app/templates folder in our project directory.
The following template would be accessed by hitting up the URL in your web browser:
http://localhost:7145/demo
<h1>hello world</h1>
Go to the Twig documentation page if you would like to familiarize yourself with Twig.
Add my own filters, globals & methods to twig
If you need to add your own filters in Twig you use the config passed to Tina4Php on running Tina4 in the index file
<?php
$config = \Tina4\Config();
/*My Custom Twig Filter */
$config->addFilter("myFilter", function ($name) {
return str_shuffle($name);
});
$config->addTwigGlobal("HELLO", "ME");
$config->addTwigFunction("getUsers", function($myvar) {
return $myvar;
});
/* End of Custom Twig Filter */
echo (new \Tina4\Tina4Php($config));
Using the filters and globals
{{ 'Hello World'|myFilter }}
{% set users = getUsers("Some Users!") %}
{{users}}
{{HELLO}}