Questions and Answers (FAQ) about creating documents in the pipeline

This guide compiles the most popular questions that our users have when editing code for documents.
Written by Владислав Пономарь
Updated 2 weeks ago
Important! If you have questions about how to interact with variables while editing documents, you can find answers in the Twig documentation. Available tags, filters, and functions are described in our reference guide.

1. How do I add today's date to the display?
{{ "now"|date("d.m.Y") }}

2. How to add + n number of days to the card creation date variable?
{{ model.created_at|date_modify("+180 day")|date("m.d.Y")}}

3. How to change the currency display of a variable from USD to dollar?

In the basic templates, variables are written as follows:

{{ product_price|format_currency('USD', locale='en') }}

To replace the currency display with «dollar», simply delete |format_currency(‘USD’, locale=‘en’) and move «dollar» outside the curly brackets:

{{ product_price }} dollar

4. How can I change the date format of an order from 2022-12-22 12:12:12 to the more familiar December 22, 2022?

Set the parameters for creating the desired variable:

{% set mnths = ['','January','February','March','April','May','June','July', 'August','September','October','November','December'] %}

After that, we write the variable itself in the right place:

{{ model.created_at|date("j") }} {{ mnths[model.created_at|date("n")] }} {{ model.created_at|date("Y") }}.

5. How do I add a product image to a template?
<img src="{{ product.picture }}" height="100">

6. How to display the amount for products in words?
{% set gtc = model.products_sum|round(0, 'floor') %}
{% set gtr = model.products_sum * 100 % 100 %}

<strong>{{ ((gtc|format_number(style="spellout", locale="en"))|capitalize) }}
 {% set currencySuffix = (gtc % 100 >= 11 and gtc % 100 <= 14) ? 'dollars' : (gtc % 10 == 1) ?
 'dollar' : (gtc % 10 >= 2 and gtc % 10 <= 4) ? 'dollar' : 'dollar' %}
{{ currencySuffix }}

 {{ gtr|format_number(locale="en") }}
 {% set centsSuffix = (gtr % 100 >= 11 and gtr % 100 <= 14) ? 'cents' : (gtr % 10 == 1) ?
'cent' : (gtr % 10 >= 2 and gtr % 10 <= 4) ? 'cents' : 'cents' %}
{{ centsSuffix }}</strong>

7. How do I get payment information from the card?

To add payment information to a document, you need to use a for loop. It allows you to get a list of all payments that are in the card and output the data of the variables you need.

An example of a list of all payments from a card with variables available for output:

{% for payment in model.payments %}
    {{ payment.payment_date }} - payment date and time
    {{ payment.type }} - payment type
    {{ payment.status }} - payment status
    {{ payment.amount }} - payment amount
    {{ payment.description }} - description
{% endfor %}

An example of displaying all records of payments made by bank card in the card with the status «Paid», indicating only the date and amount:

{% for payment in model.payments %}
    {% if payment.type == "Bank card" %}
        {% if payment.status == "paid" %}
            Date and time of payment: {{ payment.payment_date }}<br>
            Payment amount: {{ payment.amount|format_currency('USD', locale='en') }}
        {% endif %}
    {% endif %}
{% endfor %}

8. How do I take out the amount left to pay to display?
You have already paid: {% for payment in model.payments %}
{% if payment.status == "paid" %}{{ payment.amount|format_currency('USD', locale='en') }}, {% endif %}{% endfor %}

{% set paid_amount = 0 %}
{% for payment in model.payments %}
{% if payment.status == "paid" %}
{% set paid_amount = paid_amount + payment.amount %}
{% endif %}
{% endfor %}
Balance due: {{ ( model.products_sum  - paid_amount)|format_currency('USD', locale='en') }}

9. How to display cents for variable prices or amounts?

You can add currency formatting to the variable:

{{ product.price_sold|format_currency('USD', locale='en') }}

Or formatting to display 2 digits after the comma:

{{ product.price_sold|number_format(2, ',', '') }}

10. How to add price rounding?

If mathematical rounding to a smaller or larger number is required:

{{ product.price_sold|format_currency('USD', locale='en') }}

If rounding is always required to the greater value:

{{ model.grand_total|round(0, 'floor')|format_currency(currency, locale='de') }}

If rounding is always required to the lower value:

{{ model.grand_total|round(0, 'ceil')|format_currency(currency, locale='de') }}

Tags: document templates, document code, variables, code examples
Did this answer your question?