PHP code example of miladrahimi / phptemplate
1. Go to this page and download the library: Download miladrahimi/phptemplate 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/ */
miladrahimi / phptemplate example snippets
use MiladRahimi\PHPTemplate\TemplateEngineFactory;
$te = TemplateEngineFactory::create();
$te->setBaseDirectory("../Views");
$data = array(
"name" => "Bon",
"surname" => "Jovi"
);
echo $te->render("profile.html", $data);
use MiladRahimi\PHPTemplate\TemplateEngineFactory;
$te = TemplateEngineFactory::create();
$te->setBaseDirectory("../Views");
$data = array(
"name" => "Bon",
"surname" => "Jovi",
"is-admin" => true
);
echo $te->render("profile.html", $data);
use MiladRahimi\PHPTemplate\TemplateEngineFactory;
$te = TemplateEngineFactory::create();
$te->setBaseDirectory(__DIR__);
$data = array(
"name" => "David",
"surname" => "Gilmour",
"genres" => array("Progressive Rock", "Art Rock", "Blues Rock")
);
echo $te->render("singer.html", $data);
use MiladRahimi\PHPTemplate\TemplateEngineFactory;
$te = TemplateEngineFactory::create();
$te->setBaseDirectory(__DIR__);
$data = array(
"name" => "David",
"surname" => "Gilmour",
"genres" => array("Progressive Rock", "Art Rock", "Blues Rock"),
"albums" => array("On an Island" => 2006, "Rattle That Lock" => 2015)
);
echo $te->render("singer.html", $data);
use MiladRahimi\PHPTemplate\TemplateEngineFactory;
$te = TemplateEngineFactory::create();
$te->setBaseDirectory(__DIR__);
$data = array(
"name" => "David",
"surname" => "Gilmour",
"genres" => array("Progressive Rock", "Art Rock", "Blues Rock"),
"albums" => array("On an Island" => 2006, "Rattle That Lock" => 2015),
"singles" => array(
array("track" => "There's No Way Out of Here", "album" => "David Gilmour"),
array("track" => "Blue Light", "album" => "About Face"),
array("track" => "Love on the Air", "album" => "About Face")
)
);
echo $te->render("singer.html", $data);
use MiladRahimi\PHPTemplate\TemplateEngineFactory;
$te = TemplateEngineFactory::create();
$te->setBaseDirectory(__DIR__);
$data = array(
"name" => "David",
"surname" => "Gilmour",
"genres" => array("Progressive Rock", "Art Rock", "Blues Rock"),
"albums" => array("On an Island" => 2006, "Rattle That Lock" => 2015),
"singles" => array(
array("track" => "There's No Way Out of Here", "album" => "David Gilmour"),
array("track" => "Blue Light", "album" => "About Face"),
array("track" => "Love on the Air", "album" => "About Face")
),
"date" => function () {
return date("Y/m/d");
},
);
echo $te->render("singer.html", $data);
use MiladRahimi\PHPTemplate\TemplateEngineFactory;
$te = TemplateEngineFactory::create();
$te->setBaseDirectory(__DIR__);
$data = array(
"name" => "Selena",
"surname" => "Gomez",
"others" => array(
array("name" => "Taylor", "surname" => "Swift"),
array("name" => "Demi", "surname" => "Lovato")
)
);
echo $te->render("singer.html", $data);
use MiladRahimi\PHPTemplate\TemplateEngineFactory;
$te = TemplateEngineFactory::create();
$te->setBaseDirectory(__DIR__);
$data = array(
"page_title" => "Roger Waters Biography",
"name" => "Roger",
"surname" => "Waters",
);
echo $te->render("page.html", $data);