1.10. Compiler

Although Qiq templates use native PHP, the {{ ... }} syntax sugar does require a compiling process. That process is very simple, even naive, but it does exist:

  • If a compiled template already exists in the cache directory, and is newer than the source template file, the QiqCompiler returns the already-existing compiled template. Otherwise ...

  • The QiqCompiler reads the source template file, splits out the {{ ... }} tags using a regular expression, and retains them as QiqToken objects .

  • The QiqCompiler then invokes each QiqToken to get back the PHP code replacement for the {{ ... }} tag, and reassembles all the parts in order.

  • The compiled template is saved to the compiler cache directory. The same source template will not be compiled again -- at least, not until it gets re-saved, thereby updating its timestamp, making it newer than the compiled version.

1.10.1. Cache Path

The QiqCompiler cache path by default is your sys_get_temp_dir() directory appended with /qiq, but you can specify any path with Template::new():

$template = Template::new(
    cachePath: '/path/to/qiqcache/'
);

The QiqCompiler saves the compiled templates in the cache using the full path of the source template file. For example, if the cache path is /private/tmp and the source template file is at /www/site/resources/templates/foo.php, that means the compiled template file will be cached at:

/private/tmp/www/site/resources/templates/foo.php

If you see compiling errors, having the full source template path as part of the cache path will help you find the original template.

1.10.2. Cache Clearing

To clear the cache, reach into the Template to get the Compiler, and call its clear() method.

$template->getCompiler()->clear();

1.10.3. Disabling The Compiler

If you are absolutely certain that you do not want to use Qiq syntax, and will use only PHP in your template files, you can create a Template with $cachePath set to false:

$template = Template::new(
    cachePath: false
);

This will cause the Template to use the NonCompiler, which does not compile or cache template files at all.