Comment on page
Magic Code Samples
Jinja code examples for tricky things.
{% set first, last = email.split("@")[0].split(".") %}
{{ first }} {{ last }}
{% set first = email.split("@")[0] %}
{{ first }}
If you have two lists, one of which can be nested, and you want to combine items of it, do as follows:
List 1 called
list_1
:{
"items": [
{
"taxCode": "23456",
"salesTaxRate": {
"taxRate": "0.0001"
}
}
]
}
List 2 called
list_2
:{
"id": "11",
"custcol_tax_code": "23456",
"amount": 1000.00,
...
}
...
{% for line_item in list_1["items"] %}
{% for item in list_2 %}
{% if line_item.taxCode == item.custcol_tax_code %}
"line_item_id": "{{ item.item.id }}"
"amount": "{{ item.amount }}"
"tax_rate": "{{ line_item.salesTaxRate.taxRate }}"
{% endif %}
{% endfor %}
{% endfor %}
...
Since items is reserved in Python, and we use Python in the backend, you need to call it like
list_1["items"]
, rather than standard dot notation.
list_1.items is NOT possible.
Last modified 1yr ago