Jump to content

Check whether the language is RTL or LTR in TPL file


Recommended Posts

hello all.

 

 

i design a theme for prestashop 1.4 .

it support both RTL & LTR language

 

i change a few detail in tpl file .

so i need to check language is ltr or rtl in tpl file

 

 

i override classes and controllers

 

in php file

to check it

such this

 

$language = new Language($cookie->id_lang);

if ($language->is_rtl)

 

 

but i need check in a tpl file

 

someone konow how i do it

Link to comment
Share on other sites

  • 1 year later...

Hello,

 

You can access the current language id by {$cookie->id_lang} in tpl files.

 

I guess if you don't have many languages,you can hardcode what you desire by :

 

{if $cookie->id_lang eq 1}

 {* English language,therefore LTR *}
 do english processing here

{elseif $cookie->id_lang eq 2}

{* persian language,therefore RTL  -- remember to adapt id_lang of persian language *}
do other processing here

{/if}

 

 

 

But, if you really need this dynamic :

 

In tpl files,you can have access to all languages present by this global array $languages. It stores all information about the active languages.

 

So,your code might roughly look like that :

 


{foreach from=$languages item=$language}

{* i guess you'll want to know which language is active and you'll want to do some processing with that *}

{if ($cookie->id_lang eq $language.id_lang) AND $language.is_rtl eq 1}

do RTL processing here

{else}

do LTR here

{/if}

 

This should work,but i didn't test anything ;)

 

FYI :

$cookie { active cookie }

$languages { grabs available languages }

 

 

This is an old post,but hope it helps someone someday :)

Edited by martyn (see edit history)
Link to comment
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
×
×
  • Create New...