Add a slugify filter
See original GitHub issueI cannot think of a template I wrote that didn’t need such a filter 🙂
I usually write a very naive one myself:
repository_name:
type: str
help: Your repository name
default: "[[ project_name|lower|replace('_', '-')|replace(' ', '-') ]]"
But it will break in so many cases.
As an alternative, if we don’t want to support more and more filters in copier
, maybe we could think of allowing custom filters to be used. Take a look at https://github.com/mattrobenolt/jinja2-cli/pull/86, it allows this use of jinja2-cli
:
jinja2 -f ansible.plugins.filter.ipaddr.ipaddr test.txt
In copier
’s case, we would not be able to load the filter using its Python dotted-path, so we would have to think of another way to add it to the Jinja environment.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:16 (14 by maintainers)
Top Results From Across the Web
slugify Filter — Eleventy
If you need to slugify these characters, add your own universal filter with an alternative library like limax or transliteration .
Read more >slugify Filter | Django Template Tags and Filters
The slugify filter can be used to coerce an integer in to a string in a template. Consider the following use case:
Read more >Django Template Filter - slugify - W3Schools
The slugify filter returns a text into one long word containing nothing but lower case ASCII characters and hyphens (-). Meaning:.
Read more >slug - Twig - The flexible, fast, and secure PHP template engine
slug. The slug filter transforms a given string into another string that only includes safe ASCII characters. Here is an example:.
Read more >Customizable Separator for slugify - Google Groups
Sometimes it might be nice to let slugify use an underscore instead of a dash. I see that slugify is grouped with the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
As described in #277: I’d like to be able to implement custom filters for e.g. generating a secret with hmac:
I recently saw that
pyyaml
allows to load Python objects directly: https://pyyaml.org/wiki/PyYAMLDocumentation#yaml-tags-and-python-typesThe user could pass
!!python/module:my_filters
and we could add the all the functions defined in this module as filters in the jinja env, or something similar 🙂This could be useful for #182 as well.