PHP code example of eclipxe / engineworks-templates

1. Go to this page and download the library: Download eclipxe/engineworks-templates 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/ */

    

eclipxe / engineworks-templates example snippets




use EngineWorks\Templates\Callables;
use EngineWorks\Templates\Plugins;
use EngineWorks\Templates\Resolver;
use EngineWorks\Templates\Templates;

// create callables
$callables = new Callables();
$callables->attach(
    new Plugins\HtmlEscape(),
    new Plugins\FormatNumber(),
    new Plugins\Transliterate(),
);

// create resolver
$resolver = new Resolver(__DIR__ . '/templates');

// create templates
$templates = new Templates($callables, $resolver);

// fetch the content of a template (templates/user-details.php)
/* @var $user array */
$content = $templates->fetch('user-details', ['user' => $user]);

// do whatever with the response, I will just echo it
echo $content;


/**
 * @var $pagename string
 * @var $users array
 */


/* @var $templates \EngineWorks\Templates\Templates */
$templates->fetch('users-list', [
    'pagename' => 'List of users & members',
    'users' => [
        ['fullname' => 'John Doe', 'nickname' => 'jdoe'], 
        ['fullname' => 'Carlos C Soto', 'nickname' => 'eclipxe'], 
    ],
]);


/* @var $callables \EngineWorks\Templates\Callables */
/* @var $app Slim\App */
$callables->attach(new \EngineWorks\Templates\Slim\Slim4Plugin(
    $app->getRouteCollector()->getRouteParser(),
    $app->getBasePath()
));