Skip to content

Instantly share code, notes, and snippets.

@philipsharp
Last active December 28, 2015 16:29
Show Gist options
  • Save philipsharp/7529724 to your computer and use it in GitHub Desktop.
Save philipsharp/7529724 to your computer and use it in GitHub Desktop.
See: https://github.com/philipsharp/slim-view-plates for an installable package. Custom Slim Framework (http://www.slimframework.com/) view for Plates template system (http://platesphp.com/). License: MIT
<?php
$view = new \My\Views\Plates();
$view->fileExtension = 'phtml';
$app = new \Slim\Slim(array(
'view' => $view,
'templates.path' => '../templates'
));
<?php
namespace My\Views;
class Plates extends \Slim\View
{
/**
* @var \League\Plates\Engine
*/
protected $_engineInstance;
/**
* Override for the default file extension
*
* @var string
*/
public $fileExtension;
public function getInstance()
{
if (!$this->_engineInstance) {
// Create new Plates engine
$this->_engineInstance = new \League\Plates\Engine($this->getTemplatesDirectory());
if ($this->fileExtension){
$this->_engineInstance->setFileExtension($this->fileExtension);
}
}
return $this->_engineInstance;
}
public function render($template){
$platesTemplate = new \League\Plates\Template($this->getInstance());
$platesTemplate->data($this->all());
return $platesTemplate->render($template);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment