PHP code example of spin / template

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

    

spin / template example snippets


class Homepage extends Spin\Template\Template
{
	/**
	 * The template file
	 */
	protected $file = 'templates/home.php';

	/**
	 * Convert the first character of first name to uppercase on retrieval
	 */
    public function getFirstNameAttribute($value)
    {
        return ucfirst($value);
    }

	/**
	 * Convert the whole string to lowercase when setting first name
	 */
    public function setFirstNameAttribute($value)
    {
        $this->attributes['first_name'] = strtolower($value);
    }

	/**
	 * Convert the unix timestamp to a human friendly date on retrieval
	 */
	public function getDateAttribute($value)
	{
		return date('Y-m-d', $value);
	}
}

$template = new Homepage();

// Assign variables as properties
$template->first_name = 'john';
$template->date = time();

// You can also assign variables as an array
$template['weather'] = 'frightful';

// Render the template
echo $template->render();

Hello  echo $first_name; 

class Homepage extends Spin\Template\Template
{
	protected $file = 'home.twig';

	public function __construct()
	{
		$loader = new Twig_Loader_Filesystem('/path/to/templates');
		$twig = new Twig_Environment($loader);

		$this->setEngine(new Spin\Template\Engine\TwigEngine($twig));
	}
}

class Homepage extends Spin\Template\Template
{
	protected $file = 'home.smarty';

	public function __construct()
	{
		$smarty = new Smarty();
		$smarty->setTemplateDir('/path/to/templates');
		$smarty->setCompileDir('/path/to/templates_c');

		$this->setEngine(new Spin\Template\Engine\SmartyEngine($smarty));
	}
}

class Homepage extends Spin\Template\Template
{
	protected $file = 'home';

	public function __construct()
	{
		$plates = new League\Plates\Engine('/path/to/templates');

		$this->setEngine(new Spin\Template\Engine\PlatesEngine($plates));
	}
}

class Homepage extends Spin\Template\Template
{
	protected $file = 'home.dwoo';

	public function __construct()
	{
		$dwoo = new Dwoo\Core();
		$dwoo->setTemplateDir('/path/to/templates');
		$dwoo->setCompileDir('/path/to/templates_c');

		$this->setEngine(new Spin\Template\Engine\DwooEngine($dwoo));
	}
}