NetLife Guru

Setting Variables in the System

To enable dynamic content within templates, the template engine allows you to set variables that can be utilized across all templates. These variables are set using the setVariables method.

Defining Variables

Here's how you can define variables for use within your templates:

    $templateEngine->setVariables([
        'lang' => 'en',
        'title' => 'NLG template engine',
        // ... other variables
    ]);

In the code you've already established, these variables will be accessible and can be integrated throughout the template engine.

Displaying Variable Values

To display the value of a variable within your templates, use the following syntax:


    {layout}
    <!DOCTYPE html>
    <html lang="{$lang}">
    <head>

        <title>{$title}</title>
        <meta name="description" content="">
        <meta charset="UTF-8">
        ...
    {/layout}

This approach renders the respective values of `lang` and `title` variables wherever they are referenced in the template.

Defining New Variables within Templates

Besides pre-defining variables in PHP, it's also possible to define new variables directly within the template files. This feature adds an extra layer of flexibility, allowing for on-the-fly modifications and dynamic content generation based on different conditions or contexts