From 065ce96da0bdf9db232e658c948eee2e2df5dd9a Mon Sep 17 00:00:00 2001 From: Julien Bourdeau Date: Mon, 26 Sep 2016 18:44:40 +0200 Subject: [PATCH 1/4] CO: Introduce lighter fetch method for modules --- classes/module/Module.php | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/classes/module/Module.php b/classes/module/Module.php index 97f286892d659..9a43177beb5e6 100644 --- a/classes/module/Module.php +++ b/classes/module/Module.php @@ -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 @@ -2229,6 +2258,7 @@ protected function getCurrentSubTemplate($template, $cache_id = null, $compile_i $this->smarty ); } + return $this->current_subtemplate[$template.'_'.$cache_id.'_'.$compile_id]; } @@ -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(); From 069bb663b475a9dfe6ab8d1b65f946c0688d5025 Mon Sep 17 00:00:00 2001 From: Julien Bourdeau Date: Tue, 27 Sep 2016 11:13:33 +0200 Subject: [PATCH 2/4] CO: Remove unused arg for TemplateFinder --- classes/Smarty/TemplateFinder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes/Smarty/TemplateFinder.php b/classes/Smarty/TemplateFinder.php index 0b3a8ac0055e0..f5434751ef885 100644 --- a/classes/Smarty/TemplateFinder.php +++ b/classes/Smarty/TemplateFinder.php @@ -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) { From fa8042aec5998079b5ee5cca490235a103482669 Mon Sep 17 00:00:00 2001 From: Julien Bourdeau Date: Tue, 27 Sep 2016 15:00:51 +0200 Subject: [PATCH 3/4] FO: Remove wrapper feature to use the power of smarty --- classes/controller/Controller.php | 7 ----- classes/controller/ModuleFrontController.php | 28 +++----------------- themes/classic/templates/wrapper.tpl | 12 --------- 3 files changed, 4 insertions(+), 43 deletions(-) delete mode 100644 themes/classic/templates/wrapper.tpl diff --git a/classes/controller/Controller.php b/classes/controller/Controller.php index 6abdbc20c382d..ce676e30f4d92 100644 --- a/classes/controller/Controller.php +++ b/classes/controller/Controller.php @@ -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()) { diff --git a/classes/controller/ModuleFrontController.php b/classes/controller/ModuleFrontController.php index 8500a53d9c9a5..03b1a385f5793 100644 --- a/classes/controller/ModuleFrontController.php +++ b/classes/controller/ModuleFrontController.php @@ -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() diff --git a/themes/classic/templates/wrapper.tpl b/themes/classic/templates/wrapper.tpl deleted file mode 100644 index e3c0527a70e7f..0000000000000 --- a/themes/classic/templates/wrapper.tpl +++ /dev/null @@ -1,12 +0,0 @@ -{extends file=$layout} - -{* - This file is used to embed the output of some module - front controllers inside the standard layout. - If this does not make sense to you, leave this file untouched :) - In particular, this page requires no specific design or styling. -*} - -{block name='content'} - {$content nofilter} -{/block} From fe77404e0c78935fbc590433e8716676cb127c8b Mon Sep 17 00:00:00 2001 From: Julien Bourdeau Date: Tue, 27 Sep 2016 16:42:36 +0200 Subject: [PATCH 4/4] FO: add white background for default page tpl --- themes/classic/templates/index.tpl | 11 +++++++++-- themes/classic/templates/page.tpl | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/themes/classic/templates/index.tpl b/themes/classic/templates/index.tpl index ba2ab7eb00b6f..e02ef01e3532c 100644 --- a/themes/classic/templates/index.tpl +++ b/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'} +
+ {block name='page_content_top'}{/block} + {block name='page_content'} + {$HOOK_HOME nofilter} + {/block} +
+ {/block} + {/block} diff --git a/themes/classic/templates/page.tpl b/themes/classic/templates/page.tpl index 6d0544a5740e2..b9300ea4f19b0 100644 --- a/themes/classic/templates/page.tpl +++ b/themes/classic/templates/page.tpl @@ -13,7 +13,7 @@ {/block} {block name='page_content_container'} -
+
{block name='page_content_top'}{/block} {block name='page_content'}