User Tools

Site Tools


tina4:templates

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:

PHP VariableTwig Variable
$_SESSIONsession
$_REQUESTrequest
$_COOKIEcookie
$_SERVERserver

We store templates in the app/templates folder in our project directory.

The following template would be accessed by hitting up the default project URL http://localhost:7145/demo

app/templates/demo.twig
hello world

You definitely want to look at the official Twig Documentation

Add my own filters 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

index.php
$config = \Tina4\Config();
 
/*My Custom Twig Filter */
$config->addFilter("myFilter", function ($name) {
    return str_shuffle($name);
});
/* End of Custom Twig Filter */
 
echo (new \Tina4\Tina4Php($config));
tina4/templates.txt · Last modified: 2021/06/15 15:01 by andre