1. Go to this page and download the library: Download chiron/php-renderer 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/ */
chiron / php-renderer example snippets
use Chiron\Views\PhpRenderer;
tainer = $app->getContainer();
$container['renderer'] = new PhpRenderer("./templates");
$app->get('/hello/{name}', function ($request, $response, $args) use ($container) {
$text = $container->get('renderer')->render("/hello.php", $args);
return $response->write($text);
});
$app->run();
//Construct the View
$phpView = new PhpRenderer("./path/to/templates");
//Render a Template
$text = $phpView->render("/path/to/template.php", $yourData);
$response = $response->write($text);
// via the constructor
$templateVariables = [
"title" => "Title"
];
$phpView = new PhpRenderer("./path/to/templates", $templateVariables);
// or setter
$phpView->setAttributes($templateVariables);
// or individually
$phpView->addAttribute($key, $value);
$templateVariables = [
"title" => "Title"
];
$phpView = new PhpRenderer("./path/to/templates", $templateVariables);
//...
$phpView->render($template, [
"title" => "My Title"
]);
// In the view above, the $title will be "My Title" and not "Title"
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.