1. Go to this page and download the library: Download neoan3-apps/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/ */
neoan3-apps / template example snippets
use Neoan3\Apps\Template\Constants;
use Neoan3\Apps\Template\Template;
ates
Constants::setPath(__DIR__ . '/templates');
echo Template::embrace('<h1>{{test}}</h1>',['test'=>'Hello World']);
use \Neoan3\Apps\Template\Constants;
class TranslateMe
{
private string $language;
// you will receive the native DOMAttr from DOMDocument
// and the user-provided array
function __invoke(\DOMAttr &$attr, $contextData = []): void
{
// here we are going to use the "flat" version of the context data
// it translates something like
// ['en' => ['hallo'=>'hello']] to ['en.hallo' => 'hello]
$flatValues = Constants::flattenArray($contextData[$this->language]);
// if we find the content of the actual element in our translations:
if(isset($flatValues[$attr->parentNode->nodeValue])){
$attr->parentNode->nodeValue = $flatValues[$attr->parentNode->nodeValue];
}
}
function __construct(string $lang)
{
$this->language = $lang;
}
}
$html = file_get_contents(__DIR__ . '/test.html);
$contextData = [
'my' => 'value'
];
$templating = new \Neoan3\Apps\Template\Interpreter($html, $contextData);
// at this point, nothing is parsed or set if we wanted to use the attributes n-if or n-for, we would have to set it
// note how we are free to change the naming now
\Neoan3\Apps\Template\Constants::addCustomAttribute('only-if', new \Neoan3\Apps\Attributes\NIf());
// Let's parse in one step:
$templating->parse();
// And output
echo $templating->asHtml();
HTML
<h1>{{user}}</h1>
<p>{{profile.name}}</p>
<p n-for="items as key => item" n-if="key > 0">{{item}}-{{key}}</p>
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.