Merge pull request #8545 from nupplaphil/bug/subdir

Template Engine with Subdirectory
This commit is contained in:
Hypolite Petovan 2020-04-26 14:31:30 -04:00 committed by GitHub
commit 1b0a8ec5c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 8 deletions

View File

@ -99,19 +99,18 @@ class Renderer
* Load a given template $s
*
* @param string $s Template to load.
* @param string $root Optional.
* @param string $subDir Subdirectory (Optional)
*
* @return string template.
* @throws Exception
*/
public static function getMarkupTemplate($s, $root = '')
public static function getMarkupTemplate($s, $subDir = '')
{
$stamp1 = microtime(true);
$a = DI::app();
$t = self::getTemplateEngine();
try {
$template = $t->getTemplateFile($s, $root);
$template = $t->getTemplateFile($s, $subDir);
} catch (Exception $e) {
echo "<pre><b>" . __FUNCTION__ . "</b>: " . $e->getMessage() . "</pre>";
exit();

View File

@ -383,6 +383,14 @@ abstract class DI
return self::$dice->create(Util\ACLFormatter::class);
}
/**
* @return string
*/
public static function basePath()
{
return self::$dice->create('$basepath');
}
/**
* @return Util\DateTimeFormat
*/

View File

@ -68,16 +68,18 @@ class FriendicaSmartyEngine implements ITemplateEngine
return $s->parsed($template);
}
public function getTemplateFile($file, $root = '')
public function getTemplateFile($file, $subDir = '')
{
$a = DI::app();
$template = new FriendicaSmarty();
// Make sure $root ends with a slash /
if ($root !== '' && substr($root, -1, 1) !== '/') {
$root = $root . '/';
if ($subDir !== '' && substr($subDir, -1, 1) !== '/') {
$subDir = $subDir . '/';
}
$root = DI::basePath() . '/' . $subDir;
$theme = $a->getCurrentTheme();
$filename = $template::SMARTY3_TEMPLATE_FOLDER . '/' . $file;

View File

@ -27,5 +27,5 @@ namespace Friendica\Render;
interface ITemplateEngine
{
public function replaceMacros($s, $v);
public function getTemplateFile($file, $root = '');
public function getTemplateFile($file, $subDir = '');
}