Open kruncher opened 1 year ago
The following is a useful example of how Jinja2 implements custom filters: https://github.com/ONSdigital/eq-questionnaire-runner/blob/d003ab08a20294a4eba4f6bc9d8ccd42d50f8796/app/jinja_filters.py#L202
It might be problematic to use the above filter in Flask apps if the Jinja2 environment isn't created fresh for each request because identifier generation would be unique each time the same page renders. This might not be a deal breaker, but it is definitely something worth verifying first.
Tasks for this ticket:
The design system could include a default
uniqueId
filter implementation which JS/nunjucks and Python/Jinja2 projects can register for use in their templates.JS implementation:
tests:
Python implementation:
The design system getting started documentation should include a section detailing how to register the filter for use in Nunjucks and Jinja2 (by importing the provided
uniqueId
filter module from the design system).The design system can then make use of this filter to generate unique identifiers when outputting components which require automatically generated referencing:
Which would output something like this: