decap-cms
decap-cms copied to clipboard
Support filters for template strings
Is your feature request related to a problem? Please describe.
I am looking for a way to apply custom transformations on fields in template string {{ someField | filter }}
in various location in the CMS.
This would allow many cool things for usability and customizability.
Right now it is impossible to format a custom date field in for example the summary
field.
Or transform text to uppercase.
Describe the solution you'd like
I am proposing a filter mechanic similar to many other templating systems that would allow users (and the core CMS itself) to register filters that are applied on string templates similar to this:
// register filters
CMS.registerStringTemplateFilter('myFilter', whateverFunction);
CMS.registerStringTemplateFilter('date', (d, format) => moment(d).format(format));
{{ someField | myFilter }}
will be transformed internally to myFilter(someField)
and the output of that function used instead of the some_field
value.
{{ publishDate | date('YYYY-MM-DD') }}
will be transformed to date(publishDate, 'YYYY-MM-DD')
and its output used.
The convention would be to provide the field value as first parameter and all other parameters given in the filter itself as the next parameters.
The CMS core could provide filters like date
, upper
, lower
.
Describe alternatives you've considered
Additional context
I don't know and can't really justify any good argument about the performance implications of this if it's for example used in the summary
field of a large collection ¯\_(ツ)_/¯.