Prestashop Pass Controller Variables To TPL

Pass Controller Variables To TPL in Prestashop

In your Controller you can find the initContent() function, where you pass the Value to required tpl.
public function initContent()
{
 //assign value like this
  $username = 'FreemanDev';
  parent::initContent();

 //and pass here like this ( 'username' => $username)
  $smarty = $this->context->smarty;
  $smarty->assign(array(
                 'username' => $username,
          ));

  $content = $smarty->fetch(_PS_THEME_DIR_.'templates/folder/yourtpl.tpl');
  $this->context->smarty->assign(array('content' => $this->content . $content));
}
and in your tpl (yourtpl.tpl), you can access the above defined variable using curly braces with html tags or simply write.
{$username}
where ever you need it...
Thanks...

Comments

Popular posts from this blog

Prestashop Create Admin Controller inside Admin Folder

Prestashop PDF Download Error