Last active
December 28, 2015 16:29
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$view = new \My\Views\Plates(); | |
$view->fileExtension = 'phtml'; | |
$app = new \Slim\Slim(array( | |
'view' => $view, | |
'templates.path' => '../templates' | |
)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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