Skip to content

Commit

Permalink
Add a sensible default Smarty template directory
Browse files Browse the repository at this point in the history
Currently, Smarty uses the directory of the template being rendered as the root path for included partials. This currently has two issues:

1. If the template is specified using the `file:` protocol then the function will fail. **This is fixed with a specific logic check.**
2. If some other protocol is used then a nonsense path is used. **This is fixed by falling back to the theme’s view path.
  • Loading branch information
tburry committed Feb 6, 2020
1 parent 41054a2 commit 0d09fd1
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions library/core/class.smarty.php
Expand Up @@ -33,10 +33,10 @@ public function init($path, $controller) {
}

// Get an ID for the body.
$bodyIdentifier = strtolower($controller->ApplicationFolder.'_'.$controllerName.'_'.Gdn_Format::alphaNumeric(strtolower($controller->RequestMethod)));
$methodStr = Gdn_Format::alphaNumeric(strtolower($controller->RequestMethod));
$bodyIdentifier = strtolower($controller->ApplicationFolder.'_'.$controllerName).'_'.$methodStr;
$smarty->assign('BodyID', htmlspecialchars($bodyIdentifier));
$smarty->assign('DataDrivenTitleBar', Gdn::config("Feature.DataDrivenTitleBar.Enabled", false));
//$Smarty->assign('Config', Gdn::config());

// Assign some information about the user.
$session = Gdn::session();
Expand Down Expand Up @@ -74,7 +74,7 @@ public function init($path, $controller) {
}
}

$bodyClass = val('CssClass', $controller->Data, '', true);
$bodyClass = val('CssClass', $controller->Data, '');
$sections = Gdn_Theme::section(null, 'get');
if (is_array($sections)) {
foreach ($sections as $section) {
Expand Down Expand Up @@ -141,7 +141,6 @@ public function init($path, $controller) {
);

$smarty->enableSecurity($security);

}

/**
Expand All @@ -158,7 +157,20 @@ public function render($path, $controller) {
$compileID = CLIENT_NAME;
}

$smarty->setTemplateDir(dirname($path));
if (strpos($path, ':') === false) {
$smarty->setTemplateDir(dirname($path));
} else {
list($type, $arg) = explode(':', $path, 2);
if ($type === 'file') {
$smarty->setTemplateDir(dirname($arg));
} elseif (!empty($controller->Theme)) {
$smarty->setTemplateDir([
PATH_THEMES."/{$controller->Theme}/views",
PATH_ADDONS_THEMES."/{$controller->Theme}/views",
]);
}
}

$smarty->display($path, null, $compileID);
}

Expand Down

0 comments on commit 0d09fd1

Please sign in to comment.