NetLife Guru

Basic Usage of the PHP NLG Template Engine

This section provides a straightforward guide to get started with the PHP Template Engine. Here's how you can set up and render your first template:

Step 1: Loading the Engine

First, ensure that the template engine file is included in your PHP script. You can do this by requiring the engine file at the beginning of your PHP file.


    require_once "../src/aurora.php";

Step 2: Creating a New Instance

Next, create a new instance of the template engine.


    $templateEngine = new Nlg\Aurora\Loader();

Step 3: Setting Input Templates

Define the template files you want to use. In this example, we are using 'index.html' as our template.


    $templateEngine->setFiles([
        'index.html'
    ]);

Step 4: Generating Cache

For initial loading or when changes are made to your templates, enable cache creation. This helps in optimizing the rendering performance.


    $templateEngine->createCache(true);

Step 5: Rendering Output

Finally, render the template. The 'layout' specifies the starting block for rendering. In 'index.html', we have defined a 'layout' block containing 'Hello World'.


    print $templateEngine->render("layout");

The Template File (index.html)

Here's how the 'index.html' template file looks:


    {layout}
        <h1>Hello World</h1>
    {/layout}

By following these steps, you'll render a simple template that displays "Hello World". This basic setup is just the beginning of what you can achieve with the PHP Template Engine.