1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/kanboard_ynh.git synced 2024-09-03 19:36:17 +02:00
kanboard_ynh/sources/app/Core/Template.php

66 lines
1.5 KiB
PHP
Raw Normal View History

2014-07-20 12:26:15 +02:00
<?php
namespace Core;
2014-10-22 19:59:09 +02:00
use LogicException;
2014-07-20 12:26:15 +02:00
/**
* Template class
*
* @package core
* @author Frederic Guillot
*/
2015-01-16 14:23:05 +01:00
class Template extends Helper
2014-07-20 12:26:15 +02:00
{
/**
* Template path
*
* @var string
*/
2014-11-23 20:13:38 +01:00
const PATH = 'app/Template/';
2014-07-20 12:26:15 +02:00
/**
2015-01-16 14:23:05 +01:00
* Render a template
2014-07-20 12:26:15 +02:00
*
* Example:
*
2015-01-16 14:23:05 +01:00
* $template->render('template_name', ['bla' => 'value']);
2014-07-20 12:26:15 +02:00
*
* @access public
2014-10-22 19:59:09 +02:00
* @params string $__template_name Template name
* @params array $__template_args Key/Value map of template variables
2014-07-20 12:26:15 +02:00
* @return string
*/
2015-01-16 14:23:05 +01:00
public function render($__template_name, array $__template_args = array())
2014-07-20 12:26:15 +02:00
{
2014-10-22 19:59:09 +02:00
$__template_file = self::PATH.$__template_name.'.php';
2014-07-20 12:26:15 +02:00
2014-10-22 19:59:09 +02:00
if (! file_exists($__template_file)) {
throw new LogicException('Unable to load the template: "'.$__template_name.'"');
2014-07-20 12:26:15 +02:00
}
2014-10-22 19:59:09 +02:00
extract($__template_args);
2014-07-20 12:26:15 +02:00
ob_start();
2014-10-22 19:59:09 +02:00
include $__template_file;
2014-07-20 12:26:15 +02:00
return ob_get_clean();
}
/**
* Render a page layout
*
* @access public
* @param string $template_name Template name
* @param array $template_args Key/value map
* @param string $layout_name Layout name
* @return string
*/
public function layout($template_name, array $template_args = array(), $layout_name = 'layout')
{
2015-01-16 14:23:05 +01:00
return $this->render(
2014-07-20 12:26:15 +02:00
$layout_name,
2015-01-16 14:23:05 +01:00
$template_args + array('content_for_layout' => $this->render($template_name, $template_args))
2014-07-20 12:26:15 +02:00
);
}
}