Jump to content

Can't change $meta_title from module's front controller


CrayFlatline
 Share

Recommended Posts

I'm creating custom module with page. 

I have created front controller and output page. Everything is fine. But now I have to change meta title of this page and no luck. :(

 

I'm trying to make 

 

$this->context->smarty->assign(array('meta_title' => 'TEST'));

But it doesn't work and on the page I see default website's meta title. I have tried to do

$curr_meta_title = $this->context->smarty->getTemplateVars('meta_title');
var_dump($curr_meta_title);
And it outputs NULL. I think my module is processed before processing of the default meta title setting. Please help me! What I have to do to change it's behaviour and set $meta_title? 
 

Share this post


Link to post
Share on other sites

Problem is solved :) I've placed all page logic to init() instead of initContent() 

 

I created initContent() method in my module's frontController method, moved all page output code there, and now everything works :)

  • Like 1

Share this post


Link to post
Share on other sites

  • 2 years later...
  • 2 months later...

Hi hainn84,

 

I have had the same issue with a module i'm adapting and tried your solution.

It works great, thanks a lot.

 

In addition i'd say that this code seems to work only if it is placed after the {extends} directive and before the {block name='page_content'} directive, like this

{extends file='page.tpl'}

{block name='head_seo_title'}{l s='Page title' mod='yourmodulename'} | {$shop.name}{/block}

{block name='page_content'}

Need to be confirmed.

 

Thanks again

Edited by BeComWeb (see edit history)
  • Like 1

Share this post


Link to post
Share on other sites

  • 1 year later...

I'm using 1.7 and I cannot set the page title in the controller. I tried moving the code to init() but that still doesn't work. Help!

I spent hours trying to do this. Why is it so hard. I have this in initContent() but also tried init()

 $this->context->smarty->assign('meta_title',$meta_title);
 $this->context->smarty->assign('meta_description',$meta_description);
  $this->context->smarty->assign('meta_keywords',$meta_keyword);

Share this post


Link to post
Share on other sites

  • 3 years later...
On 4/22/2019 at 3:52 PM, dronedude said:

I'm using 1.7 and I cannot set the page title in the controller. I tried moving the code to init() but that still doesn't work. Help!

I spent hours trying to do this. Why is it so hard. I have this in initContent() but also tried init()

 $this->context->smarty->assign('meta_title',$meta_title);
 $this->context->smarty->assign('meta_description',$meta_description);
  $this->context->smarty->assign('meta_keywords',$meta_keyword);

Hi,
It's been a while since this question, but I had to do the same (1.7.8).
In your front controller :
 

    public function getTemplateVarPage()
    {
        $page = parent::getTemplateVarPage();
        $page['meta']['title'] = 'Your Title';
        return $page;
    }

 

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More