Di seguito un elenco delle principali funzioni di utility
- cast
- createSlug
- decode
- fetchAndCache
- formatLocalizedDate
- getCountries
- getCountry
- getDeviceInfo
- getRequestHeaders
- getState
- json
- jsondecode
- lang
- redirect
- sendEmail
- shuffle
- var_dump
Converte una variable al tipo specificato
cast(string,cast_type)
| param | type | note | default |
|---|---|---|---|
| string | string | La variabile da convertire | |
| cast_type | string | int, float, oppure bool |
{% set number = cast('123456', 'int') %}
Data una stringa, la converte in una stringa utilizzabile come url
createSlug(string)
| param | type | note | default |
|---|---|---|---|
| string | string |
{{ createSlug("Nome del prodotto") }}
nome-del-prodotto
Equivalente a php htmlspecialchars_decode, va usato come filtro
decode()
{{ string | htmlspecialchars_decode }}
Recupera il contenuto di un URL e lo memorizza in cache
fetchAndCache(url)
| param | type | note | default |
|---|---|---|---|
| url | string | HTTP o HTTPS URL |
Utilizzato quando è necessario recuperare contenuti html da un url di terze parti
Formatta una data nel formato desiderato
formatLocalizedDate(timestamp,format)
| param | type | note | default |
|---|---|---|---|
| timestamp | int | Unix timestamp | |
| format | string | Date format |
Restituisce tutte le nazioni della piattaforma
getCountries()
[
...,
{
"_id":"4f13da27be85f1d82600000d",
"uid":14,
"tld":"AU",
"name":"Australia"
},
{
"_id":"4f13da27be85f1d82600000e",
"uid":15,
"tld":"AT",
"name":"Austria"
},
...
]
Dato l'uid di una nazione, ne restituisce il nome
getCountry(countryUID)
| param | type | note | default |
|---|---|---|---|
| countryUID | int |
{{ getCountry(119) }}
Italia
Ottenere le informazioni sul device corrente
getDeviceInfo()
{"type":"desktop","sys_type":""}
{"type":"mobile","sys_type":"android"}
{"type":"mobile","sys_type":"ios"}
{"type":"tablet","sys_type":"ios"}
Ricava gli header con cui è stata eseguita la chiamata alla pagina corrente
getRequestHeaders()
{
"Host":"test-ssl.mystoreden.com",
"Connection":"close",
"Authorization":"Basic c3Rsdn2m21kZr3246XXGVzd2A=",
"User-Agent":"PostmanRuntime\/7.42.0",
"Accept":"*\/*",
"Cache-Control":"no-cache",
"Postman-Token":"b0f1d790-6bb3-480a-83f6-458aa34d96db",
"Accept-Encoding":"gzip,deflate, br"
}
Dato l'uid di una città, ne restituisce il nome
getState(stateUID)
| param | type | note | default |
|---|---|---|---|
| stateUID | int |
{{ getState(123465) }}
Treviso
Json encode
json()
{% set j = variable | json %}
Json decode
jsondecode()
{% set j = variable | jsondecode %}
Data una chiave di traduzione, fornisce l'equivalente testuale
lang(key)
| param | type | note | default |
|---|---|---|---|
| key | string |
{{ lang('page.home') }}
Homepage
Redirect ad uno specifico URL
redirect(http_code)
| param | type | note | default |
|---|---|---|---|
| http_code | int | 301, 302 |
{% if condition %}
// redirect to /shop page with HTTP code 301
{{ '/shop' | redirect(301) }}
{% endif %}
Invia una mail
sendEmail(from,subject,message,fromMessage,email)
| param | type | note | default |
|---|---|---|---|
| from | string | E-mail del cliente che scrive | |
| subject | string | Oggetto della mail | |
| message | string | Contenuto della mail, accetta HTML | |
| fromMessage | string | FromName | |
| string | E-mail destinatario. Se vuoto il destinatario è l'indirizzo e-mail principale del negozio | ||
| reply_to_email | string | E-mail destinatario per la risposta |
Se il form che raccoglie i dati da inviare nella mail è inviato in POST e contiene file, questi verranno aggiunti come allegati alla mail.
Array shuffle
shuffle()
{% set list = ["a", "b", "c"] | shuffle %}
Filtro, stampa a video la variabile
var_dump()
{{ variable | var_dump }}
Commenti