PHP code example of sitepoint / templating-engine

1. Go to this page and download the library: Download sitepoint/templating-engine 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/ */

    

sitepoint / templating-engine example snippets


 $this->parent('app::layout', ['title' => 'Blog Post: '.$title]); 

use SitePoint\TemplatingEngine\TemplatingEngine;

$engine = new TemplatingEngine(
    ['app'  => '/path/to/templates/app'], // The namespaces to register
    ['caps' => 'strtoupper'],             // Function callbacks to register inside the template context
    'phtml'                               // The extension of the templates (defaults to phtml)
);

$params = [
    'title' => 'My Blog Post',
    'paragraphs' => [
        'My first paragraph.',
        'My second paragraph.',
    ],
];

echo $engine->render('app::post', $params);

/**
 * Define a parent template.
 *
 * @param string $template The name of the parent template.
 * @param array  $params   Parameters to add to the parent template context
 *
 * @throws EngineException If a parent template has already been defined.
 */
public function parent($template, array $params = []);

/**
 * Insert a template.
 *
 * @param string $template The name of the template.
 * @param array  $params   Parameters to add to the template context
 */
public function insert($template, array $params = []);

/**
 * Render a block.
 *
 * @param string $name The name of the block.
 */
public function block($name, callable $callback = null);

/**
 * Escape a string for safe output as HTML.
 *
 * @param string $raw The unescaped string.
 *
 * @return string The escaped HTML output.
 */
public function escape($raw);