PHP code example of corex / template

1. Go to this page and download the library: Download corex/template library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

corex / template example snippets


// Set base path (can be called more than once). Paths will be searched in reverse order.
Template::basePath('/path/to/templates');
Template::basePath('/path/to/other/templates');

// Load template.
$template = Template::load('test');

// Set escape on variables (default un-escaped).
$template->escape();

// Set path for templates.
$template->path('/path/to/some/other/templates');

// Set variable on template.
$template->variable('myVar', 'myValue');
$template->var('myVar2', 'myValue2');

// Set variables.
$template->variables([
    'myVar1' => 'myValue1',
    'myVar2' => 'myValue2'
]);
$template->vars([
    'myVar3' => 'myValue3',
    'myVar4' => 'myValue4'
]);

// Render template.
$content = $template->render();

// Example of loading template, set var and render.
$content = Template::load('base')
    ->variable('myVar', 'myValue')
    ->var('myVar2', 'myValue2')
    ->render();

// Render template directly.
$content = Template::render('base', [
    'myVar1' => 'myValue1',
    'myVar2' => 'myValue2'
]);

// Parse template and render values.
$content = Template::parse('({{myVar}})', ['myVar' => 'myValue']);

// Get Mustache engine.
$mustacheEngine = Template::mustacheEngine();