Post by DesignCart » Tue May 22, 2018 12:03 am

Hi
I use Opencart 2.3 and i need variable with language code in header.tpl file.
I use this code (I found this code in this forum)

echo $this->session->data['language'];

but it causes an error.

<b>Notice</b>: Undefined property: Template\PHP::$session in <b>C:\xampp7\htdocs\immunology-shop\catalog\view\theme\immunology\template\common\header.tpl</b> on line <b>102</b><b>Notice</b>: Trying to get property of non-object in <b>C:\xampp7\htdocs\immunology-shop\catalog\view\theme\immunology\template\common\header.tpl</b> on line <b>102</b>

Somebody help me? Please :)

my website: Tworzenie sklepu internetowego


User avatar
Active Member

Posts

Joined
Thu Nov 10, 2016 2:06 pm
Location - Gubin

Post by yodapt » Tue May 22, 2018 12:59 am

Template files are outside the scope of that variable (should be worth reading about if you want to develop anything), if you want to use it you need to declare it in the respective controller and then use it in the template, like so.

controller

Code: Select all

$this->data['language'] = $this->session->data['language'];
template

Code: Select all

<?php echo $language; ?>

Opencart Developer - My Extension Showcase
Contact me at aeon.yoda@gmail.com


User avatar
Active Member

Posts

Joined
Fri Jun 17, 2011 6:39 pm


Post by DesignCart » Tue May 22, 2018 11:34 am

Ok I paste in controller header code:
$data['language'] = $this->session->data['language'];
and
code echo $language;
in header.tpl not work.

Are You sure. It not work for me?

my website: Tworzenie sklepu internetowego


User avatar
Active Member

Posts

Joined
Thu Nov 10, 2016 2:06 pm
Location - Gubin
Who is online

Users browsing this forum: No registered users and 264 guests