2013-02-18 03:48:21 +01:00
|
|
|
<?php
|
|
|
|
|
2016-08-25 03:17:58 +02:00
|
|
|
namespace Miniflux\Template;
|
2013-02-18 03:48:21 +01:00
|
|
|
|
2016-12-26 15:44:53 +01:00
|
|
|
use Miniflux\Model;
|
|
|
|
|
2016-08-19 03:26:50 +02:00
|
|
|
const PATH = 'app/templates/';
|
2013-02-18 03:48:21 +01:00
|
|
|
|
|
|
|
// Template\load('template_name', ['bla' => 'value']);
|
|
|
|
function load()
|
|
|
|
{
|
|
|
|
if (func_num_args() < 1 || func_num_args() > 2) {
|
|
|
|
die('Invalid template arguments');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! file_exists(PATH.func_get_arg(0).'.php')) {
|
|
|
|
die('Unable to load the template: "'.func_get_arg(0).'"');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (func_num_args() === 2) {
|
|
|
|
if (! is_array(func_get_arg(1))) {
|
|
|
|
die('Template variables must be an array');
|
|
|
|
}
|
|
|
|
|
|
|
|
extract(func_get_arg(1));
|
|
|
|
}
|
|
|
|
|
|
|
|
ob_start();
|
|
|
|
include PATH.func_get_arg(0).'.php';
|
|
|
|
return ob_get_clean();
|
|
|
|
}
|
|
|
|
|
2013-10-06 23:33:37 +02:00
|
|
|
function layout($template_name, array $template_args = array(), $layout_name = 'layout')
|
2013-02-18 03:48:21 +01:00
|
|
|
{
|
2016-12-26 15:44:53 +01:00
|
|
|
return load(
|
|
|
|
$layout_name,
|
|
|
|
$template_args + array('content_for_layout' => load($template_name, $template_args))
|
|
|
|
);
|
2014-03-17 02:56:43 +01:00
|
|
|
}
|