1. Go to this page and download the library: Download ttek/tk-domtemplate 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/ */
ttek / tk-domtemplate example snippets
// Load a template with some valid SCSS inline:
// <style type="text/scss"> .. </style>
// or with a standard css te as needed ...
// final step befor rendering to the output stream is to execute andy DOM modifiers
$dm = new \Tk\Dom\Modifier\Modifier();
$dm->add(new \Tk\Dom\Modifier\Filter\Scss(
$basePath, // site base path from the vendor dir
$baseUrl, // base url from the vbendor path
$cachePath, // path to cache the compiled css files
// add any SCSS properties you may want to access in the source files during parsing
$constants = [
'backColor' => '#EFEFEF',
'borderWidth' => '1px',
]
));
// modifier to move all JS to the bottom of the page
$dm->add(new \Tk\Dom\Modifier\Filter\JsLast();
$dm->execute($template->getDocument());
echo $template->toString();
// Load a new template from a file. (The file must be XHTML valid or errors will be produced)
$template = new \Dom\Template::loadFile('index.html');
// Add some text content inside the anchor node
$template->insertText('link', 'This is a link');
//Add some HTML content inside the ancor node
$template->insertHtml('link', '<i class="fa fa-times"></i> Close');
// Add a real URL to the ancor
$template->setAttr('link', 'href', 'http://www.example.com/');
...
// Load a new template from a file. (The file must be XHTML valid or errors will be produced)
$template = new \Dom\Template::loadFile('index.html');
// Add some text content inside the anchor node
$template->setVisible('showNode');
...
// Load a new template from a file. (The file must be XHTML valid or errors will be produced)
$template = new \Dom\Template::loadFile('index.html');
$list = array(
'Link 1' => 'http://www.example.com/link1.html',
'Link 2' => 'http://www.example.com/link2.html',
'Link 3' => 'http://www.example.com/link3.html',
'Link 4' => 'http://www.example.com/link4.html'
);
// Loop through the data and render each item
foreach($list as $text => $url) {
$repeat = $template->getRepeat('item');
$repeat->insertText('url', $text);
$repeat
// Finish the repeat item and append it to its parent.
$repeat->appendRepeat();
}
...
$template = \Dom\Template::load($buff);
// Set the pageTitle tag --> <h1 var="pageTitle">Default Text</h1>
$template->setText('pageTitle', 'Dynamic Form Example');
$domForm = $template->getForm('contactForm');
// Init any form elements to a default status
$select = $domForm->getFormElement('country');
/* @var $select \Dom\Form\Select */
$select->appendOption('-- Select --', '');
$select->appendOption('New Zealand', 'NZ');
$select->appendOption('England', 'UK');
$select->appendOption('Australia', 'AU');
$select->appendOption('America', 'US');
$select->setValue('AU');
...
// Then you can set the value from the request if you like....
$domForm->getFormElement('name')->setValue($_REQUEST['name']);
$domForm->getFormElement('email')->setValue($_REQUEST['email']);
$domForm->getFormElement('country')->setValue($_REQUEST['country']);
$domForm->getFormElement('comments')->setValue($_REQUEST['comments']);
// * Setup the Template loader, create adapters to look for templates as needed
/* @var \Dom\Loader $dl */
$dl = \Dom\Loader::getInstance();
$dl->addAdapter(new \Dom\Loader\Adapter\DefaultAdapter());
$dl->addAdapter(new \Dom\Loader\Adapter\ClassPath($config->getAppPath().'/html/xml'));