question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add a slugify filter

See original GitHub issue

I 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:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:16 (14 by maintainers)

github_iconTop GitHub Comments

1reaction
baurmattcommented, Sep 25, 2020

As described in #277: I’d like to be able to implement custom filters for e.g. generating a secret with hmac:

import binascii, hashlib, hmaci
hmac.new(binascii.unhexlify(key), msg.encode(), hashlib.sha256).hexdigest()
1reaction
pawamoycommented, Jun 24, 2020

I recently saw that pyyaml allows to load Python objects directly: https://pyyaml.org/wiki/PyYAMLDocumentation#yaml-tags-and-python-types

The 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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found