Opencart:如何基于语言加载不同的CSS样式

问题描述 投票:2回答:1

我使用opencart我想在语言为ar时加载stylesheet-rtl.css,在语言为en时加载stylesheet.css

我试过这个和其他一些我在互联网上找到但它不起作用?

<?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 }?>

有什么帮助吗?

php html opencart opencart-3
1个回答
2
投票

direction中有一个header.php变量:

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

您可以在视图文件中使用它,编辑此文件:

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

找:

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

替换为:

{% 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 %}

然后清除你的主题和ocmod缓存。

© www.soinside.com 2019 - 2024. All rights reserved.