PHP code example of satori / template
1. Go to this page and download the library: Download satori/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/ */
satori / template example snippets
declare(strict_types=1);
namespace App;
use Satori\Template\AbstractTemplate;
class LayoutTemplate extends AbstractTemplate
{
protected $layoutBlock = '/app/layout';
protected $commonVars = [];
protected $layoutVars = [];
protected function init(array $data)
{
$company = $this->params['company'];
$this->commonVars['company'] = $company;
$this->layoutVars['app_name'] = $company;
$this->layoutVars['title'] = $company;
$this->layoutVars['copyright'] = date('Y') . ' ' . $company;
}
}
declare(strict_types=1);
namespace Page;
use App\LayoutTemplate;
class ReadTemplate extends LayoutTemplate
{
protected $headBlock = '/app/head';
protected $contentBlock = '/page/read';
protected $headVars = [];
protected $contentVars = [];
protected function init(array $data)
{
parent::init($data);
$page = $data['page'];
$this->layoutVars['title'] = $page->title;
$this->headVars['description'] = $page->description;
$this->contentVars['page'] = $page;
}
}
declare(strict_types=1);
use Page\ReadTemplate;
$page = new stdClass();
$page->title = 'About';
$page->description = 'About company';
$page->name = 'About us';
$page->content = 'The company is the market leader';
$template = new ReadTemplate(
'/template',
['company' => 'My company']
);
echo $template->render(['page' => $page]);
html
$_ = 8
html
$_ = 12