PHP code example of phpolar / php-templating

1. Go to this page and download the library: Download phpolar/php-templating 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/ */

    

phpolar / php-templating example snippets


$page = new Page();
$safeContext = new HtmlSafeContext($page);
$templateEng->render("path/to/template.php", $safeContext);
// or...
echo $templateEng->apply("path/to/template", $safeContext /* optional */);

// or...
echo $templateEng->apply("template", $safeContext /* optional */);
// or...
echo $templateEng->apply("template", $safeContext /* optional */);

// template.php

<!DOCTYPE html>

/**
 * @var Page $view
 */
$view = $this;

// Page.php

class Page
{
    public string $title;

    public string $backgroundColor = "#fff";

    public string $font = "Arial";

    public function __construct(string $title)
    {
        $this->title = $title;
    }
}

bash
composer