Themes built on the Twig templating engine are now deprecated and require migration to Vitrin to ensure continued support and compatibility with Zid.
.twig
and .html
to .jinja
Twig | Jinja |
---|---|
raw | safe |
json_encode() | tojson |
filter | select or reject |
url_encode | urlencode |
Twig (function) | Jinja (filter) |
---|---|
asset_url | asset_url |
assetUrl | asset_url |
strReplace | replace(search, replace) |
datetimeFormat(date: string, format: string = 'Y-m-d H:i:s’, locale: string = null) | def format_datetime( |
datetime: _Instant = None, | |
format: _PredefinedTimeFormat | str = 'medium', |
tzinfo: datetime.tzinfo | None = None, |
locale: Locale | str |
) -> str: | |
from babel.dates | |
timeFormat(time: string, format: string = 'g:i a’, locale: string = null) | def format_time( |
time: datetime.time | datetime.datetime |
format: _PredefinedTimeFormat | str = 'medium', |
tzinfo: datetime.tzinfo | None = None, |
locale: Locale | str |
) -> str: | |
from babel.dates |
Twig | Jinja |
---|---|
requestAdd(query: dict) | replace with direct session.url.include_query_params(**params) |
requestGet | replace with direct session.query_params.get() |
requestUri | session.url.path |
requestInputs | session.url.params |
urlWithQuery | replace with direct session.url.include_query_params(**params) |
rangeN | use python’s default range() function |
rangeNWithStep | use python’s default range() function |
tDate | - no equivalent - |
- no equivalent - | def url_for( |
name: str, | |
*, | |
localize: bool = True, | |
query_params: dict[str, str] | None = None, |
**path_params, | |
) -> str: | |
””” | |
returns a path for the requested operation name | |
e.g. url_for("list_products") | |
””” | |
Twig | Jinja | |
---|---|---|
paginated response standards | response.data | |
response.total | ||
response.current_page | ||
… | ||
response.last_page | ||
response.results | ||
response.count | ||
response.page | ||
response.page_size | ||
response.pages_count | ||
description | Twig | Jinja | notes |
---|---|---|---|
null safety | ?? | or or ` | default('')` |
you can pass true default('', true) to force falsy values (None , '' , 0 , empty list, False , etc.) as “missing” and substitute with default. | |||
null | None | ||
create a small, local context for an included template | {% include … with {…} only %} | {% with … %} | |
{% include … %} | |||
{% endwith %} | |||
translations | locals.hello_world | _(”Hello world”) | locals.{something} is not twig syntax but rather a mapping passed in context |
{% schema %}
to {}_schema.json
file with same name. And remove them from the jinja filelocals.
to _('english text')
based on en.json
, and then create a .po
file with the Arabic translations from ar.json
to replace the json files. Then arguments passed to _
function should be moved to string formatting.vitrin:{template}