Skip to content

price_base

The price_base macro is used to render a single price with an optional label on the page.

Definition

{% price_base(price, label, classNames) %}

Input parameters

price

string represents a price to render.

label

string if set, an additional price label will be displayed.

classNames

object An object of additional class parameters that will be appended to specific elements:

Option key Type Default Required Description
classNames.price string "" no Classes that will be appended to the main base price element
classNames.priceLabel string "" no Classes that will be appended to the label of the base price
classNames.priceValue string "" no Classes that will be appended to the price value element of the base price

Example

In this example we render a price with a label.

{% from "@macros/price_base.twig" import price_base %}

{{ price_base('$12.34', 'My label') }}

Example

In this example we render a price with an additional class added to the price value element.

{% from "@macros/price_base.twig" import price_base %}

{{ price_base('$12.34', '', {
    priceValue: 'color_success-600'
}) }}

Macro source code

{% macro price_base(price, label = '', classNames = {})  %}
    <div class="price {{ classNames.price }}">
        {% if label %}
            <span class="price__label {{ classNames.priceLabel }}">{{ label }}</span>
        {% endif %}

        <span class="price__value {{ classNames.priceValue }}">{{ price }}</span>
    </div>
{% endmacro %}