language_and_currency_indicator¶
The language_and_currency_indicator
macro is used to indicate which language and currency is currently active in the shop.
Definition¶
Input parameters¶
shopLanguage¶
Locale
A currently active language in the shop in a form of a Locale object from ObjectApi.
shopCurrency¶
Currency
A currently active currency in the shop in a form of a Currency object from ObjectApi.
options (optional)¶
object
represents the object of configuration options for the macro which consists of the following fields:
Option key | Type | Default | Required | Description |
---|---|---|---|---|
options.isFlagPositionLeft | boolean |
false | no | If set to true the flag position will be on the left side of the language, otherwise it will be on the top |
Example¶
In this example we use ObjectApi methods to get a current language and currency from the shop. We also display a flag on the left side instead by passing the isFlagPositionLeft
options parameter.
{% from "@macros/language_and_currency_indicator.twig" import language_and_currency_indicator %}
{% set shopLanguage = ObjectApi.getShopLocale() %}
{% set shopCurrency = ObjectApi.getShopCurrency() %}
{{ language_and_currency_indicator(shopLanguage, shopCurrency, { isFlagPositionLeft: true }) }}
Macro source code¶
{% macro language_and_currency_indicator(shopLanguage, shopCurrency, options) %}
{% from "@macros/separator.twig" import separator %}
<div
class="
language-and-currency__modal-opener
{% if options.isFlagPositionLeft %}language-and-currency__modal-opener_horizontal{% endif%}
"
>
<img src="/assets/img/flags/{{ shopLanguage.locale }}.png" alt="Flag" class="language-and-currency__flag" />
<div class="language-and-currency__label p_xs">
{{ shopLanguage.name }}
{{ options.isFlagPositionLeft ? separator({ horizontal: true, size: 's' }) : '/' }}
{{ shopCurrency.symbol|default(shopCurrency.shortName) }}
</div>
</div>
{% endmacro %}