ilario Posted September 20, 2017 Share Posted September 20, 2017 ciao you know the name of the variable, the page title (the title meta)I need to see the name in a form $page_title = $this->context->smarty->tpl_vars['page']->value['page_name']; meta_title ??????????????']; thank you so muchIlario Link to comment Share on other sites More sharing options...
catalin.pop Posted September 21, 2017 Share Posted September 21, 2017 (edited) In template the variable is {$page.meta.title}In php $this->context->controller->cms->meta_title This is for Prestashop 1.7 Edited September 21, 2017 by catalin.pop (see edit history) Link to comment Share on other sites More sharing options...
ilario Posted September 21, 2017 Author Share Posted September 21, 2017 public function hookdisplayPageTitle() { $page_title = ''; $id_lang = (int)$this->context->language->id; $page = $this->context->smarty->tpl_vars['page']->value['page_name']; if (Tools::getIsset('id_category') && $page == 'category') { $id_cat = Tools::getValue('id_category'); $category = new Category($id_cat); $page_title = $category->name[$id_lang]; $page_title = explode(' ', $page_title); } else if (Tools::getIsset('id_product') && $page == 'product') { $id_prod = Tools::getValue('id_product'); $product = new Product($id_prod); $page_title = $product->name[$id_lang]; $page_title = explode(' ', $page_title); } else $page_title = $this->context->controller->$page->meta_title; $this->context->smarty->assign( array('page_title' => $page_title) ); return $this->display(__FILE__, 'owlpagetitle.tpl'); } thanks for the answer, but it works in half. I attach the code to it, it works with all page - cms, but with other page, contact , cart, login etc. does not show the title Link to comment Share on other sites More sharing options...
catalin.pop Posted September 21, 2017 Share Posted September 21, 2017 From your code I see you're using $page_title = $this->context->controller->$page->meta_title; Have you tried replacing it with ? $page_title = $this->context->controller->cms->meta_title; Link to comment Share on other sites More sharing options...
ilario Posted September 21, 2017 Author Share Posted September 21, 2017 perfect!!!! thank you very much Link to comment Share on other sites More sharing options...
ilario Posted September 22, 2017 Author Share Posted September 22, 2017 unfortunately today does not work, it only makes me cms and not all the others Link to comment Share on other sites More sharing options...
catalin.pop Posted September 22, 2017 Share Posted September 22, 2017 So in other words it worked yesterday but not today? Link to comment Share on other sites More sharing options...
ilario Posted September 22, 2017 Author Share Posted September 22, 2017 yes yesterday worked for other pages, today only for the "cms" page I did not make any other fixes, if I did not try to override the file,also cleared the cache, then tried to put it back in the form's folder but nothing Link to comment Share on other sites More sharing options...
catalin.pop Posted September 22, 2017 Share Posted September 22, 2017 try this see what's printing $page_title = $this->context->controller->page->meta->title; Link to comment Share on other sites More sharing options...
ilario Posted September 22, 2017 Author Share Posted September 22, 2017 nothing unfortunately, it does not work even more for cms pages Link to comment Share on other sites More sharing options...
catalin.pop Posted September 22, 2017 Share Posted September 22, 2017 if you do a var_dump on $this->context->controller->page what does return? var_dump($this->context->controller->page); Link to comment Share on other sites More sharing options...
ilario Posted September 23, 2017 Author Share Posted September 23, 2017 return "Nul" Link to comment Share on other sites More sharing options...
catalin.pop Posted September 23, 2017 Share Posted September 23, 2017 ok. I've tested and this is what is working for me.I think the best way to do it is like this From a FrontController (MyController extends FronController) $page_name = $this->getPageName(); $meta_tags = Meta::getMetaTags($this->context->language->id, $page_name); print_r($meta_tags); will print Array ( [meta_title] => Cart [meta_description] => [meta_keywords] => ) I called this from CartController that's why the title is Cart Second solution using Smarty vars print_r($this->context->smarty->tpl_vars['page']); will print Smarty_Variable Object ( [value] => Array ( [title] => [canonical] => [meta] => Array ( [title] => Cart [description] => [keywords] => [robots] => index ) [page_name] => cart [body_classes] => Array ( [lang-en] => 1 [lang-rtl] => [country-US] => 1 [currency-USD] => 1 [layout-full-width] => 1 [page-cart] => 1 [tax-display-disabled] => 1 ) [admin_notifications] => Array ( ) ) [nocache] => [scope] => 0 ) If you ask me the first solution is much more clean because you're not forced to rely on context and you can get meta information about other pages Let me know if this is working Link to comment Share on other sites More sharing options...
ilario Posted September 23, 2017 Author Share Posted September 23, 2017 the first solution does not work as an error, the second prints all the variables, but in English, can you add a language parameter? Smarty_Variable Object ( [value] => Array ( [title] => [canonical] => [meta] => Array ( [title] => My account [description] => [keywords] => [robots] => index ) [page_name] => my-account [body_classes] => Array ( [lang-it] => 1 [lang-rtl] => [country-IT] => 1 [currency-EUR] => 1 [layout-full-width] => 1 [page-my-account] => 1 [tax-display-enabled] => 1 ) [admin_notifications] => Array ( ) ) [nocache] => [scope] => 0 ) thanks Link to comment Share on other sites More sharing options...
catalin.pop Posted September 23, 2017 Share Posted September 23, 2017 What error did the first code return? The second code is based on $this->context and if the context is set for English then the English title will be returned. If you call the controller after you change the language it will show the title in that language? Btw, from there did you execute the code? Link to comment Share on other sites More sharing options...
ilario Posted September 24, 2017 Author Share Posted September 24, 2017 1) What error did the first code return? first code freezes page load 2) The second code is based on $this->context and if the context is set for English then the English title will be returned. If you call the controller after you change the language it will show the title in that language? italiano id2 <Btw, from there did you execute the code? modulo this is code complete <?php /** * 2007-2017 PrestaShop * * NOTICE OF LICENSE * * This source file is subject to the Academic Free License (AFL 3.0) * that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://opensource.org/licenses/afl-3.0.php * If you did not receive a copy of the license and are unable to * obtain it through the world-wide-web, please send an email * to [email protected] so we can send you a copy immediately. * * DISCLAIMER * * Do not edit or add to this file if you wish to upgrade PrestaShop to newer * versions in the future. If you wish to customize PrestaShop for your * needs please refer to http://www.prestashop.com for more information. * * @author PrestaShop SA <[email protected]> * @copyright 2007-2017 PrestaShop SA * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) * International Registered Trademark & Property of PrestaShop SA * */ if (!defined('_CAN_LOAD_FILES_')) exit; class OwlPagetitleoverride extends Module { private $temp_url = '{owlpagetitle_url}'; private $html; private $settings_default; private $wt_manu_config; private $config; public function __construct() { $this->name = 'owlpagetitle'; $this->tab = 'front_office_features'; $this->version = '1.0.0'; $this->author = 'owltheme'; $this->bootstrap = true; parent::__construct(); $this->displayName = $this->trans('OWL Page Title'); $this->description = $this->trans('Get page title'); } public function install() { if (!parent::install() || !$this->registerHook('displayPageTitle')) return false; return true; } public function hookdisplayPageTitle() { $page_title = ''; $id_lang = (int)$this->context->language->id; $page = $this->context->smarty->tpl_vars['page']->value['page_name']; if (Tools::getIsset('id_category') && $page == 'category') { $id_cat = Tools::getValue('id_category'); $category = new Category($id_cat); $page_title = $category->name[$id_lang]; $page_title = explode(' ', $page_title); } else if (Tools::getIsset('id_product') && $page == 'product') { $id_prod = Tools::getValue('id_product'); $product = new Product($id_prod); $page_title = $product->name[$id_lang]; $page_title = explode(' ', $page_title); } else /******** here code for other page ***********/ $this->context->smarty->assign( array('page_title' => $page_title) ); return $this->display(__FILE__, 'owlpagetitle.tpl'); } } Link to comment Share on other sites More sharing options...
catalin.pop Posted September 24, 2017 Share Posted September 24, 2017 public function hookdisplayPageTitle() { $page_title = ''; $id_lang = (int)$this->context->language->id; $page = $this->context->smarty->tpl_vars['page']->value['page_name']; echo($id_lang." : "+$page); see what $id_lang and $page prints? if the information is ok try $meta_tags = Meta::getMetaTags($id_lang, $page); Link to comment Share on other sites More sharing options...
ilario Posted September 25, 2017 Author Share Posted September 25, 2017 ok perfect thank you very very much $meta_tags = Meta::getMetaTags($id_lang, $page); print_r($meta_tags['meta_title']); but I only have a small problem, I have three pages: contact-us cart my account, which I can not translate, even the title in the bar is always in English Link to comment Share on other sites More sharing options...
catalin.pop Posted September 25, 2017 Share Posted September 25, 2017 http://doc.prestashop.com/display/PS17/SEO+and+URLs maybe this will help you? Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now