Skip to content

Instantly share code, notes, and snippets.

@meysampg
Created September 2, 2015 06:19
Show Gist options
  • Save meysampg/0a6524b13b8be8e6205a to your computer and use it in GitHub Desktop.
Save meysampg/0a6524b13b8be8e6205a to your computer and use it in GitHub Desktop.
Automatic load rtl.css for RTL languages in PrestaShop
{* Check for RTL langguages and automatically load rtl.css from CSS folder of theme for RTL languages. *}
{foreach from=$languages key=k item=language name="languages"}
{if ($cookie->id_lang == $language.id_lang) && (1 == $language.is_rtl)}
<link rel="stylesheet" href="{$css_dir}rtl.css" type="text/css" media="screen" />
{break}
{/if}
{/foreach}
@meysampg
Copy link
Author

meysampg commented Sep 2, 2015

An example of use this code on header.tpl file:

{if isset($css_files)}                                                                                                                          
        {foreach from=$css_files key=css_uri item=media}                                                                                        
                <link rel="stylesheet" href="{$css_uri|escape:'html':'UTF-8'}" type="text/css" media="{$media|escape:'html':'UTF-8'}" />        
        {/foreach}                                                                                                                              

        {* Check for RTL langguages and automatically load rtl.css from CSS folder of theme for RTL languages. *}                               
        {foreach from=$languages key=k item=language name="languages"}                                                                          
                {if ($cookie->id_lang == $language.id_lang) && (1 == $language.is_rtl)}                                                         
                        <link rel="stylesheet" href="{$css_dir}rtl.css" type="text/css" media="screen" />                                       
                        {break}                                                                                                                 
                {/if}                                                                                                                           
        {/foreach}                                                                                                                              
{/if}

@meysampg
Copy link
Author

meysampg commented Sep 2, 2015

PrestaShop 1.6 has a bulit-in detector for RTL languages :)) https://github.com/PrestaShop/PrestaShop/blob/1.6/classes/controller/FrontController.php#L1035

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment