PHP code example of ride / lib-template

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

    

ride / lib-template example snippets




use ride\library\template\engine\EngineModel;
use ride\library\template\engine\ThemeModel;
use ride\library\template\TemplateFacade;

function foo(EngineModel $engineModel, ThemeModel $themeModel) {
    $resource = 'path/to/resource';
    $variables = array('var1' => 'value1');

    // template facade should be made available by your implementation
    $templateFacade = TemplateFacade($engineModel, $themeModel);
    $templateFacade->setDefaultEngine('smarty');
    $templateFacade->setDefaultTheme('my-theme');

    // a simple template rendering
    $template = $templateFacade->createTemplate($resource, $variables);
    $template->set('var2', 'value2');

    $output = $templateFacade->render($template);

    // a template for a non-default theme
    $template = $templateFacade->createTemplate($resource, $variables, 'overriden-theme');

    // a template for a non-default theme with a specific engine
    $template = $templateFacade->createTemplate($resource, $variables, 'overriden-theme', 'my-engine');

    // get the file representation of a specific template
    $file = $templateFacade->getFile($template); // ride\library\system\file\File

    // get's the available template for a specific namespace
    $engine = null;
    $theme = null;
    $templates = $templateFacade->getFiles('path/to', $engine, $theme);
    echo $engine; // smarty
    echo $theme; // my-theme

    // reads the meta from the template comments in the beginning of the resource
    // syntax: [key: value([; key: value])*]
    // eg for Smarty: {* name: My Title; action: index *}
    // will return array('name' => 'My Title', 'action' => 'index')
    $meta = $templateFacade->getTemplateMeta($template);
}