Example #1
0
<?php

/**
 * Example: example will show you how the DotTemplate can be used
 * 
 * This example contains simple variable and block parsing
 * 
 */
include '../src/Exception/HaltException.php';
include '../src/DotTemplate.php';
// root directory is .
// remove the unknown / undefined {VARIABLES}
// no fallback
// no predefined page content
$tpl = new DotTemplate('.', 'remove');
// alternate version
// using ../templates because the setRoot won't help in this case as we get file contents manually
#$tpl = new Dot_Template('.', 'remove', '', ['tpl_main'=>file_get_contents('../templates/index.tpl')]);
// set the root directory
$tpl->setRoot(dirname(__DIR__) . '/templates/');
// set the main variable the template is working on (usually tpl_main)
$mainVar = 'tpl_main';
// load file contents in to main variable
$tpl->setFile($mainVar, 'index.tpl');
// setting
$tpl->setVar('VARIABLE', 'This is the variable inside');
// values to parse within block
$values = [1, 2, 3, 4, 7];
// setting the block
$tpl->setBlock($mainVar, 'test_block', 'internal_block_var');
// parsing the block
Example #2
0
 /** @dataProvider provideStringTemplateRU */
 public function testStringTplRU($pageContent, $expectedPageContent)
 {
     $tpl = new DotTemplate('.', 'remove', '', ['tpl_main' => $pageContent]);
     $this->assertEquals($tpl->get('tpl_main'), $expectedPageContent);
 }