gantry / gantry5

:rocket: Next Generation Template / Theme Framework
http://gantry.org
1.04k stars 204 forks source link

Grav - Add support for Grav Twig Filters #2351

Open DamirPecnik opened 6 years ago

DamirPecnik commented 6 years ago

Users are requesting to be able to use Grav Twig Filters in Gantry. Will this be possible to implement?

mahagr commented 6 years ago

I've already added a few. The issue is that Gantry is using different context than Grav, mostly because of Gantry and Grav aren't fully compatible with each other on all details.

DamirPecnik commented 6 years ago

Are they documented in documentation?

mahagr commented 6 years ago

More like in changelog.

Here's list of all Gantry specific filters:

html            Filter stream URLs (gantry-theme://images/image.jpeg) from the HTML and convert them into real URLs
url         Similar to Grav filter, but more powerful
trans_key(...)      Translate: `field.description|trans_key('GANTRY5_FORM_FIELD', scope, name, 'DESC')`
trans           Translate: `'GANTRY5_FORM_FIELD'|trans`
repeat(n)       Repeat string n times
values          Same as `array_values()` in PHP
base64          Base64 encode string
imagesize(true)     Returns image size as an array: `{"width": 150, "height": 100}`
imagesize(false)    Returns image size as HTML attribute: ``
truncate_text(limit)    Remove HTML and truncate string
attribute_array     Converts array into HTML attributes: `['data-id' => 'id', 'data-key' => 'key']` => ' `data-id="id" data-key="key"'`

and filters that are also in Grav:

fieldName       Convert dot notation to html input name: 'data.value.1' to 'data[value][1]'
json_decode     Decode JSON into an array
truncate_html       Truncate HTML (summary)
markdown        Render text as markdown
string          Cast value to string
int         Cast value to integer
bool            Cast value to boolean
float           Cast value to float
array           Cast value to array

Feel free to add them into the documentation.