Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework template calls for module #6491

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion classes/Smarty/TemplateFinder.php
Expand Up @@ -49,7 +49,7 @@ public function getTemplate($template, $entity, $id, $locale)
{
$locale = (Validate::isLocale($locale)) ? $locale : '';

$templates = $this->getTemplateHierarchy($template, $entity, $id, $locale);
$templates = $this->getTemplateHierarchy($template, $entity, $id);

foreach ($this->directories as $dir) {
foreach ($templates as $tpl) {
Expand Down
7 changes: 0 additions & 7 deletions classes/controller/Controller.php
Expand Up @@ -541,13 +541,6 @@ protected function smartyOutputContent($content)
$html = $this->context->smarty->fetch($content, null, $this->getLayout());
}

if ($this->controller_type === 'modulefront') {
// Modules do not know about the layout system,
// let's inject their output inside the front-end layout.
$this->context->smarty->assign('content', $html);
$html = $this->context->smarty->fetch('wrapper.tpl');
}

$html = trim($html);

if (in_array($this->controller_type, array('front', 'modulefront')) && !empty($html) && $this->getLayout()) {
Expand Down
28 changes: 4 additions & 24 deletions classes/controller/ModuleFrontController.php
Expand Up @@ -55,31 +55,11 @@ public function __construct()
*/
public function setTemplate($template, $params = array(), $locale = null)
{
if (!$path = $this->getTemplatePath($template)) {
throw new PrestaShopException("Template '$template' not found");
}

$this->template = $path;
}

/**
* Finds and returns module front template that take the highest precedence.
*
* @param string $template Template filename
*
* @return string|false
*/
public function getTemplatePath($template)
{
if (Tools::file_exists_cache(_PS_THEME_DIR_.'modules/'.$this->module->name.'/'.$template)) {
return _PS_THEME_DIR_.'modules/'.$this->module->name.'/'.$template;
} elseif (Tools::file_exists_cache(_PS_THEME_DIR_.'modules/'.$this->module->name.'/views/templates/front/'.$template)) {
return _PS_THEME_DIR_.'modules/'.$this->module->name.'/views/templates/front/'.$template;
} elseif (Tools::file_exists_cache(_PS_MODULE_DIR_.$this->module->name.'/views/templates/front/'.$template)) {
return _PS_MODULE_DIR_.$this->module->name.'/views/templates/front/'.$template;
if (strpos($template, 'module:') === 0) {
$this->template = $template;
} else {
parent::setTemplate($template, $params, $locale);
}

return false;
}

public function initContent()
Expand Down
35 changes: 30 additions & 5 deletions classes/module/Module.php
Expand Up @@ -2213,6 +2213,35 @@ public function display($file, $template, $cache_id = null, $compile_id = null)
}
}

/**
* Use this method to return the result of a smarty template when assign data only locally with $this->smarty->assign()
*
* @param string $templatePath relative path the template file, from the module root dir.
* @param null $cache_id
* @param null $compile_id
*
* @return mixed
*/
public function fetch($templatePath, $cache_id = null, $compile_id = null)
{
if ($cache_id !== null) {
Tools::enableCache();
}

$template = $this->context->smarty->createTemplate(
$templatePath,
$cache_id,
$compile_id,
$this->smarty
);

if ($cache_id !== null) {
Tools::restoreCacheSettings();
}

return $template->fetch();
}

/**
* @param string $template
* @param string|null $cache_id
Expand All @@ -2229,6 +2258,7 @@ protected function getCurrentSubTemplate($template, $cache_id = null, $compile_i
$this->smarty
);
}

return $this->current_subtemplate[$template.'_'.$cache_id.'_'.$compile_id];
}

Expand Down Expand Up @@ -2264,11 +2294,6 @@ public function getTemplatePath($template)
}
}

protected function _getApplicableTemplateDir($template)
{
return $this->_isTemplateOverloaded($template) ? _PS_THEME_DIR_ : _PS_MODULE_DIR_.$this->name.'/';
}

public function isCached($template, $cache_id = null, $compile_id = null)
{
Tools::enableCache();
Expand Down
11 changes: 9 additions & 2 deletions themes/classic/templates/index.tpl
@@ -1,5 +1,12 @@
{extends file='page.tpl'}

{block name='page_content'}
{$HOOK_HOME nofilter}
{block name='page_content_container'}
<section id="content" class="page-home">
{block name='page_content_top'}{/block}
{block name='page_content'}
{$HOOK_HOME nofilter}
{/block}
</section>
{/block}

{/block}
2 changes: 1 addition & 1 deletion themes/classic/templates/page.tpl
Expand Up @@ -13,7 +13,7 @@
{/block}

{block name='page_content_container'}
<section id="content" class="page-content">
<section id="content" class="page-content card card-block">
{block name='page_content_top'}{/block}
{block name='page_content'}
<!-- Page content -->
Expand Down
12 changes: 0 additions & 12 deletions themes/classic/templates/wrapper.tpl

This file was deleted.