Post by al404 » Mon Oct 17, 2016 7:49 pm

Hi was looking for a way to echo a specific piece of code based on selected language
i found this question

viewtopic.php?f=21&t=28364

but is not working anymore in opencast 2

in my theme/template/common/header.tpl i found that $lang echo the correct value but it doesn't work in product template

New member

Posts

Joined
Fri May 04, 2012 4:29 pm

Post by knowband.plugins » Mon Oct 17, 2016 11:02 pm

Following variable will give you code of the selected language.
$this->session->data['language']

But you cannot use it directly in a .tpl file. You need to assign its value first in controller of the tpl file.

You can use below code to assign its value to a variable.

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

Regards,
Knowband Team

Opencart Plugins: Knowband Store
Email: support@knowband.com


User avatar
Active Member

Posts

Joined
Thu Aug 04, 2016 2:56 pm


Post by al404 » Wed Oct 19, 2016 1:10 am

it works but i don't really like the idea to modify the controller

i can't understand why the variable I have in header.tmp is not available any more

New member

Posts

Joined
Fri May 04, 2012 4:29 pm

Post by knowband.plugins » Wed Oct 19, 2016 5:15 pm

Since you can't use this session function in 2.0 version's tpl files, you must need to edit controller file to assign its value to a variable.

In version less than 2.0, you can use it directly in tpl files.

Regards,
Knowband Team

Opencart Plugins: Knowband Store
Email: support@knowband.com


User avatar
Active Member

Posts

Joined
Thu Aug 04, 2016 2:56 pm


Post by Johnathan » Wed Oct 19, 2016 10:32 pm

The language code should also be stored in a separate cookie, so you should be able to access it in the template file by doing this:

Code: Select all

<?php $language_code = $_COOKIE['language']; ?>

Image
Image Image Image Image


User avatar
Global Moderator

Posts

Joined
Fri Dec 18, 2009 3:08 am


Post by tingwing » Tue Jul 25, 2017 11:01 pm

if use cookie,it always shows the same language,even if you have changed your current language

my email :support@bestshop24h.com
my wechat:bestshop24h
my extension:https://www.opencart.com/index.php?rout ... estshop24h


Active Member

Posts

Joined
Tue Aug 02, 2016 9:01 pm

Post by tingwing » Wed Jul 26, 2017 9:57 am

1)go to /catalog/controller/product/product.php after

$data['heading_title'] = $product_info['name'];
add

$data['clanguage'] = $this->session->data['language'];
go to /catalog/view/theme/default/template/product/product.tpl

add the following code to where you want it to display.

<?php echo $clanguage; ?>
now,if you select "English" ,it will show "en-gb",if you select "简体中文",it will show "zh-cn".

my email :support@bestshop24h.com
my wechat:bestshop24h
my extension:https://www.opencart.com/index.php?rout ... estshop24h


Active Member

Posts

Joined
Tue Aug 02, 2016 9:01 pm

Post by fyg50 » Wed Dec 13, 2017 12:51 am

tingwing wrote:
Wed Jul 26, 2017 9:57 am
1)go to /catalog/controller/product/product.php after

$data['heading_title'] = $product_info['name'];
add

$data['clanguage'] = $this->session->data['language'];
go to /catalog/view/theme/default/template/product/product.tpl

add the following code to where you want it to display.

<?php echo $clanguage; ?>
now,if you select "English" ,it will show "en-gb",if you select "简体中文",it will show "zh-cn".

Hello, thank you very much for this info, it really worked :)
Web site: https://www.erkekgiyim.com
Respects :)

Newbie

Posts

Joined
Wed Dec 13, 2017 12:47 am

Post by Intcorp » Wed Oct 31, 2018 2:09 pm

Is there solution to show some content on language conditions for opencart 3.0?

Newbie

Posts

Joined
Thu Oct 11, 2018 9:31 pm

Post by Johnathan » Wed Oct 31, 2018 9:14 pm

If you need a different page for a different language, why not just use an information page with different translations? It should let you enter content for each language, so you can customize it however you want.

If you don't need an entire page, but just a banner or module with different content, you should be able to use an HTML module for that. It also lets you assign content for each language, so you can display different things conditionally, based on the customer's language choice.

If you need something that doesn't go in a specific module position, but is embedded within some other content, you'll need to use tingwing's edit above. You modify the controller file, and then add the corresponding variable in the template file. If that's too complicated for you, I do have an Infinite Module Positions extension that lets you hook modules onto any HTML element on a page. That should let you put an HTML module anywhere you want. Feel free to take a look at the screenshots and demo site, and if you're interested let me know at www.getclearthinking.com/contact if you have any further questions.

Image
Image Image Image Image


User avatar
Global Moderator

Posts

Joined
Fri Dec 18, 2009 3:08 am

Who is online

Users browsing this forum: No registered users and 6 guests