Escaping

TIt is sometimes desirable or even necessary to have Tplix ignore sections it would otherwise parse. A classic example is embedding Javascript or CSS code in a template. The problem arises as those languages use the { and } characters which are also the default delimiters for Tplix.

A good practice for avoiding escapement altogether is by separating your Javascript/CSS into their own files and use standard HTML methods to access them. This will also take advantage of browser script caching. When you need to embed Tplix variables/functions into your Javascript/CSS, then the following applies.

In Tplix templates, the { and } braces will be ignored so long as they are surrounded by white space. This behavior can be disabled by setting the Tplix class variable $auto_literal to false.

<script>
   // the following braces are ignored by Tplix
   // since they are surrounded by whitespace
   function foobar {
    alert('foobar!');
   }
   // this one will need literal escapement
   {literal}
    function bazzy {alert('foobar!');}
   {/literal}
</script>

{literal}..{/literal} blocks are used for escaping blocks of template logic. You can also escape the braces individually with {ldelim}, {rdelim} tags or {$tplix.ldelim},{$tplix.rdelim} variables.

Was this article helpful?