Skip to content

address

The address macro is used to render a formatted address block, including name, street, city, country, phone number, and email.

Definition

{% address(options) %}

Input parameters

options

object represents an object of address options

Option key Type Default Required Description
options.name string "" no The name to display.
options.addressLine1 string "" no The first line of the street address to display.
options.addressLine2 string "" no The second line of the street address to display.
options.zipCode string "" no The postal code to display.
options.city string "" no The city name to display.
options.country.name string "" no The country name to display.
options.phoneNumber string "" no The phone number to display.
options.email string "" no The email address to display.

Example

Here is an example of a basic address

{% from "@macros/address.twig" import address %}
{{ address({
    name: 'Shoper',
    addressLine1: 'ul. Pawia 9',
    zipCode: '31-154',
    city: 'Kraków',
    country: { name: 'Polska' },
    phoneNumber: '+48 501 509 509',
    email: 'pomoc@shoper.pl'

 }) }}

Macro source code

{% macro address(address) %}
    <address class="font_size-m font_normal mb-xs-2">
        {% if address.name %}
            <p class="address-line p p_no-margin"><strong>{{ address.name }}</strong></p>
        {% endif %}
        {% if address.addressLine1 %}
            <p class="address-line p p_no-margin">{{ address.addressLine1 }}</p>
        {% endif %}
        {% if address.addressLine2 %}
            <p class="address-line p p_no-margin">{{ address.addressLine2 }}</p>
        {% endif %}
        {% if address.zipCode or address.city or address.country.name %}
            <p class="address-line p p_no-margin">{% if address.zipCode %}{{ address.zipCode }} {% endif %}{% if address.city %}{{ address.city }}{% endif %}{% if address.country.name %}, {{ address.country.name }}{% endif %}</p>
        {% endif %}
    </address>

    {% if address.phoneNumber or address.email %}
        <p class="font_size-m">
            {% if address.phoneNumber %}
                <a href="tel:{{ address.phoneNumber }}" class="link link_regular link_no-underline d-block">{{ address.phoneNumber }}</a>
            {% endif %}
            {% if address.email %}
                <a href="mailto:{{ address.email }}" class="link link_regular link_no-underline">{{ address.email }}</a>
            {% endif %}
        </p>
    {% endif %}
{% endmacro %}