Access to $sl variable

Third Party Plugins to CMSimple - how to install, use and create plugins

Moderator: Tata

Post Reply
milkodb
Posts: 47
Joined: Sun Jun 23, 2013 11:00 pm
Location: Italy

Access to $sl variable

Post by milkodb » Mon Sep 05, 2022 5:26 am

Hi,

I have to create a site in two languages ​​and some of the pages are loaded with the "wrapper" plugin. From these I can't access the $sl variable which returns the currently active language since the $sl variable of Cmsimple_xh is in the window.top and is not declared in the page loaded with "wrapper" from which I should retrieve it. This page is a php which in turn loads an html template. The labels in the two languages ​​must be loaded from external files which could be js files or php files. But using js I read in window.top the variable $sl and the data to be loaded works in the next page of the html template but it does not work in the php page which is loaded before the html template. And it's no surprise to me as php code runs before js one. But with php I have the problem that I have no idea how to access the $sl variable of Cmsimple_xh which is in parent of the php page loaded with "wrapper".
Using a cookie doesn't work because the delay in write / read returns an inverted result when loading the included page.

In summary: I use "wrapper" to include an external html page. Before this page a php page is loaded which builds some parts of the other page (basically it's all based on "PHPSlideShow"). So, my problem to solve is to retrieve from these pages the language that has been chosen through the "menulanguage" of the site template and load the corresponding file (php or js) with the variables of the texts in the correct language.

How can I do?

Thanks in advance for any suggestions.
Milko

cmb
Posts: 14225
Joined: Tue Jun 21, 2011 11:04 am
Location: Bingen, RLP, DE
Contact:

Re: Access to $sl variable

Post by cmb » Mon Sep 05, 2022 5:18 pm

Many templates basically start with

Code: Select all

<html lang="<?=$sl;?>">
, so you should be able to get the value of the lang attribute of the html element (something like window.top.document.documentElement.lang). If your template does not include the lang attribute, you should modify it.

There are other ways to pass the value of $sl, but this should be the most simplistic and probably the cleanest solution.
Christoph M. Becker – Plugins for CMSimple_XH

milkodb
Posts: 47
Joined: Sun Jun 23, 2013 11:00 pm
Location: Italy

Re: Access to $sl variable

Post by milkodb » Mon Sep 05, 2022 6:57 pm

Hi cmb, thanks for the reply.

Perfect solution.

I also saw that the problem would also be solved by registering a cookie directly from the template page of the site and from this there does not seem to be any delay problems in the pages included with "wrapper". However, your solution is certainly simpler and avoids any complications in loading times. Well, also because in both cases I avoid js and do everything in php without having to pass variables from one code to another.

A thousand thanks. :)
Milko

Post Reply