Search code examples
phphtmlopencartopencart-3

Opencart : How To Load Different CSS Style, Based On Language


I use opencart I want to load stylesheet-rtl.css when language is ar and stylesheet.css when language is en

i tried this and some others i found in internet but it doesn't work ?

<?php if($direction == "rtl"){?>
    <link href="catalog/view/theme/tt_palora1/stylesheet/style.css" rel="stylesheet">
<?php } else { ?>
    <link href="catalog/view/theme/tt_palora1/stylesheet/stylesheet.css" rel="stylesheet">
<?php }?>

any help please ?


Solution

  • There is a direction variable in header.php:

    $data['direction'] = $this->language->get('direction');
    

    You can use it in your view file, edit this file:

    catalog\view\theme\your-theme\template\common\header.twig
    

    Find:

    <link href="catalog/view/theme/your-theme/stylesheet/stylesheet.css" rel="stylesheet">
    

    Replace it with:

    {% if direction == 'rtl' %}
        <link href="catalog/view/theme/your-theme/stylesheet/stylesheet-rtl.css" rel="stylesheet">
    {% else %}
        <link href="catalog/view/theme/your-theme/stylesheet/stylesheet.css" rel="stylesheet">
    {% endif %}
    

    Then clear your theme and ocmod caches.