NetLife Guru

Setting Language Constants

The template engine also supports the definition of language constants, which are crucial for internationalization and localization. These constants are similar to variables but are specifically used for language-related strings.

Defining Language Constants

Language constants are defined using the setLanguageConstants method, where each constant is assigned a corresponding value in an associative array:


    $templateEngine->setLanguageConstants([
        'hello world' => 'Hello World',
        // ... other language constants
    ]);

This method allows for defining multiple language constants that can be easily managed and updated.

Using Language Constants in Templates

In the templates, language constants are referenced using a specific syntax with backticks ``. This syntax differentiates language constants from regular variables.

Example of referencing a language constant in a template:

    {layout}
        {`hello world`}
    {/layout}
Hello World

Output on Screen

When the above template is rendered, it will output the value associated with the 'hello world' constant. In this case, the output on the screen would be:


    Hello World