Compare commits
2 commits
c0c5deedda
...
dc7655bceb
Author | SHA1 | Date | |
---|---|---|---|
|
dc7655bceb | ||
|
76b134d747 |
4 changed files with 72 additions and 39 deletions
10
example/templates/empty.tpl
Normal file
10
example/templates/empty.tpl
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
{extends file='TplCore:empty.tpl'}
|
||||||
|
{block name="navbar-extra-content"}
|
||||||
|
<form class="d-flex" role="search" action='item'>
|
||||||
|
<div class="input-group input-group-sm me-2">
|
||||||
|
<input class="form-control" type="search" name="pattern"
|
||||||
|
placeholder="{t}Search{/t}" aria-label="{t}Search{/t}">
|
||||||
|
<span class="input-group-text"><i class="fa fa-search" aria-hidden="true"></i></span>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
{/block}
|
16
src/Tpl.php
16
src/Tpl.php
|
@ -160,6 +160,7 @@ class Tpl {
|
||||||
self :: $smarty->setTemplateDir(self :: $core_templates_directory);
|
self :: $smarty->setTemplateDir(self :: $core_templates_directory);
|
||||||
self :: $smarty->setCompileDir($templates_c_dir);
|
self :: $smarty->setCompileDir($templates_c_dir);
|
||||||
self :: $smarty->registerResource('Tpl', new TplSmartyResource());
|
self :: $smarty->registerResource('Tpl', new TplSmartyResource());
|
||||||
|
self :: $smarty->registerResource('TplCore', new TplSmartyResource(true));
|
||||||
$debug_ajax = App::get('templates.debug_ajax', null, 'bool');
|
$debug_ajax = App::get('templates.debug_ajax', null, 'bool');
|
||||||
self :: $_debug_ajax = boolval($debug_ajax);
|
self :: $_debug_ajax = boolval($debug_ajax);
|
||||||
Log :: register_fatal_error_handler(array('\\EesyPHP\\Tpl', 'fatal_error'));
|
Log :: register_fatal_error_handler(array('\\EesyPHP\\Tpl', 'fatal_error'));
|
||||||
|
@ -617,10 +618,13 @@ class Tpl {
|
||||||
/**
|
/**
|
||||||
* Resolve templates path against registered templates directories
|
* Resolve templates path against registered templates directories
|
||||||
* @param string $path
|
* @param string $path
|
||||||
|
* @param bool $core_only Core only mode (optional, default: false)
|
||||||
* @return string|false
|
* @return string|false
|
||||||
*/
|
*/
|
||||||
public static function resolve_templates_path($path) {
|
public static function resolve_templates_path($path, $core_only=false) {
|
||||||
foreach(array_keys(self :: $templates_directories) as $dir) {
|
foreach(array_keys(self :: $templates_directories) as $dir) {
|
||||||
|
if ($core_only && $dir != self :: $core_templates_directory)
|
||||||
|
continue;
|
||||||
$fullpath = "$dir/$path";
|
$fullpath = "$dir/$path";
|
||||||
if (file_exists($fullpath)) {
|
if (file_exists($fullpath)) {
|
||||||
Log::trace('Templates file "%s" resolved as "%s"', $path, $fullpath);
|
Log::trace('Templates file "%s" resolved as "%s"', $path, $fullpath);
|
||||||
|
@ -635,11 +639,12 @@ class Tpl {
|
||||||
* Return the content of a Smarty template file.
|
* Return the content of a Smarty template file.
|
||||||
*
|
*
|
||||||
* @param string $template The template name (eg: base.tpl)
|
* @param string $template The template name (eg: base.tpl)
|
||||||
|
* @param bool $core_only Core only mode (optional, default: false)
|
||||||
*
|
*
|
||||||
* @return string The content of the Smarty template file
|
* @return string The content of the Smarty template file
|
||||||
**/
|
**/
|
||||||
public static function get_template_source($template) {
|
public static function get_template_source($template, $core_only=false) {
|
||||||
$path = self :: resolve_templates_path($template);
|
$path = self :: resolve_templates_path($template, $core_only);
|
||||||
if (!is_readable($path)) {
|
if (!is_readable($path)) {
|
||||||
// No error return with Smarty3 and highter because it's call
|
// No error return with Smarty3 and highter because it's call
|
||||||
// template name in lower first systematically
|
// template name in lower first systematically
|
||||||
|
@ -653,11 +658,12 @@ class Tpl {
|
||||||
* template file.
|
* template file.
|
||||||
*
|
*
|
||||||
* @param string $template The template name (eg: empty.tpl)
|
* @param string $template The template name (eg: empty.tpl)
|
||||||
|
* @param bool $core_only Core only mode (optional, default: false)
|
||||||
*
|
*
|
||||||
* @return int|null The timestamp of the last change of the Smarty template file
|
* @return int|null The timestamp of the last change of the Smarty template file
|
||||||
**/
|
**/
|
||||||
public static function get_template_timestamp($template) {
|
public static function get_template_timestamp($template, $core_only=false) {
|
||||||
$path = self :: resolve_templates_path($template);
|
$path = self :: resolve_templates_path($template, $core_only);
|
||||||
if (is_file($path)) {
|
if (is_file($path)) {
|
||||||
$time = filemtime($path);
|
$time = filemtime($path);
|
||||||
if ($time)
|
if ($time)
|
||||||
|
|
|
@ -11,10 +11,17 @@ use Smarty_Resource_Custom;
|
||||||
*/
|
*/
|
||||||
class TplSmartyResource extends Smarty_Resource_Custom {
|
class TplSmartyResource extends Smarty_Resource_Custom {
|
||||||
|
|
||||||
// prepared fetch() statement
|
// Core only templates
|
||||||
protected $fetch;
|
protected $core_only;
|
||||||
// prepared fetchTimestamp() statement
|
|
||||||
protected $mtime;
|
/**
|
||||||
|
* Constructor
|
||||||
|
* @param bool $core_only Core only mode (optional, default: false)
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct($core_only=false) {
|
||||||
|
$this -> core_only = $core_only;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch a template and its modification time
|
* Fetch a template and its modification time
|
||||||
|
@ -25,8 +32,8 @@ class TplSmartyResource extends Smarty_Resource_Custom {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
protected function fetch($name, &$source, &$mtime) {
|
protected function fetch($name, &$source, &$mtime) {
|
||||||
$source = Tpl :: get_template_source($name);
|
$source = Tpl :: get_template_source($name, $this -> core_only);
|
||||||
$mtime = Tpl :: get_template_timestamp($name);
|
$mtime = Tpl :: get_template_timestamp($name, $this -> core_only);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -39,6 +46,6 @@ class TplSmartyResource extends Smarty_Resource_Custom {
|
||||||
* @return integer timestamp (epoch) the template was modified
|
* @return integer timestamp (epoch) the template was modified
|
||||||
*/
|
*/
|
||||||
protected function fetchTimestamp($name) {
|
protected function fetchTimestamp($name) {
|
||||||
return Tpl :: get_template_timestamp($name);
|
return Tpl :: get_template_timestamp($name, $this -> core_only);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,16 +31,23 @@
|
||||||
{block name="body"}
|
{block name="body"}
|
||||||
|
|
||||||
{block name="navbar"}
|
{block name="navbar"}
|
||||||
<header class="p-3 mb-3 border-bottom">
|
<header>
|
||||||
<div class="container">
|
<nav class="{block name="navbar-class"}navbar navbar-expand-lg{/block}" {block name="navbar-extra-args"}{/block}>
|
||||||
<div class="d-flex flex-wrap align-items-center justify-content-center justify-content-lg-start">
|
<div class="{block name="navbar-container-class"}container{/block}">
|
||||||
{block name="navbar-brand"}
|
{block name="navbar-brand"}
|
||||||
<a href="/" class="d-flex align-items-center mb-2 mb-lg-0 text-dark text-decoration-none">
|
<a class="navbar-brand me-3" href="#">
|
||||||
<img id="logo" src="{static_url path="images/logo.svg"}" alt="Logo" title="Logo"/>
|
<img id="logo" src="{static_url path="images/logo.svg"}" alt="Logo" title="Logo"/>
|
||||||
</a>
|
</a>
|
||||||
{/block}
|
{/block}
|
||||||
|
|
||||||
<ul class="pr-2 nav col-12 col-lg-auto me-lg-auto mb-2 justify-content-center mb-md-0">
|
<button class="navbar-toggler" type="button" data-bs-toggle="collapse"
|
||||||
|
data-bs-target="#navbar-menu" aria-controls="navbar-menu" aria-expanded="false"
|
||||||
|
aria-label="Toggle navigation">
|
||||||
|
<span class="navbar-toggler-icon"></span>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<div class="collapse navbar-collapse" id="navbar-menu">
|
||||||
|
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
|
||||||
{block name="navbar-menu"}
|
{block name="navbar-menu"}
|
||||||
{/block}
|
{/block}
|
||||||
</ul>
|
</ul>
|
||||||
|
@ -49,9 +56,10 @@
|
||||||
|
|
||||||
{block name="navbar-user"}
|
{block name="navbar-user"}
|
||||||
{if isset($auth_user) && $auth_user}
|
{if isset($auth_user) && $auth_user}
|
||||||
<div class="dropdown text-end">
|
<ul class="navbar-nav text-end">
|
||||||
|
<li class="nav-item dropdown">
|
||||||
{block name="navbar-user-name"}
|
{block name="navbar-user-name"}
|
||||||
<a href="#" class="d-block link-dark text-decoration-none dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
|
<a class="nav-link active dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
|
||||||
<i class="fa fa-user-circle" aria-hidden="true"></i>
|
<i class="fa fa-user-circle" aria-hidden="true"></i>
|
||||||
{$auth_user->name|escape:"htmlall"}
|
{$auth_user->name|escape:"htmlall"}
|
||||||
</a>
|
</a>
|
||||||
|
@ -61,21 +69,23 @@
|
||||||
{block name="navbar-user-menu-content"}{/block}
|
{block name="navbar-user-menu-content"}{/block}
|
||||||
<li>
|
<li>
|
||||||
<a class="dropdown-item" href="logout">
|
<a class="dropdown-item" href="logout">
|
||||||
<i class="fas fa-sign-out-alt"></i> {t domain=$CORE_TEXT_DOMAIN}Sign out{/t}
|
<i class="fa fa-sign-out"></i> {t domain=$CORE_TEXT_DOMAIN}Sign out{/t}
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
{/block}
|
{/block}
|
||||||
</div>
|
</li>
|
||||||
|
</ul>
|
||||||
{/if}
|
{/if}
|
||||||
{/block}
|
{/block}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
</header>
|
</header>
|
||||||
{/block}
|
{/block}
|
||||||
|
|
||||||
{block name="main"}
|
{block name="main"}
|
||||||
<main class="flex-shrink-0">
|
<main class="flex-shrink-0 mt-2">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
{block name="pagetitle"}{if $pagetitle}<h1 class="mt-5">{$pagetitle}</h1>{/if}{/block}
|
{block name="pagetitle"}{if $pagetitle}<h1 class="mt-5">{$pagetitle}</h1>{/if}{/block}
|
||||||
{include file='Tpl:errors.tpl'}
|
{include file='Tpl:errors.tpl'}
|
||||||
|
|
Loading…
Reference in a new issue