StringExtension

Description

StringExtension provides the standard string functions.

class jinjazzle.ext.string.StringExtension(environment)

Jinja2 extension for string manipulation.

jinjazzle.ext.string.slugify(lhs, **kwargs)

Slugifies the value with python-slugify

https://pypi.org/project/python-slugify/

Make a slug from the given text.

Parameters:
  • (str) (regex_pattern) – initial text

  • (bool) (allow_unicode) – converts html entities to unicode (foo & bar -> foo-bar)

  • (bool) – converts html decimal to unicode (Ž -> Ž -> z)

  • (bool) – converts html hexadecimal to unicode (Ž -> Ž -> z)

  • (int) (max_length) – output string length

  • (bool) – truncates to end of full words (length may be shorter than max_length)

  • (bool) – if parameter is True and max_length > 0 return whole words in the initial order

  • (str) – separator between words

  • (iterable) (replacements) – words to discount

  • (str) – regex pattern for disallowed characters

  • (bool) – activate case sensitivity by setting it to False

  • (iterable) – list of replacement rules e.g. [[‘|’, ‘or’], [‘%’, ‘percent’]]

  • (bool) – allow unicode characters

Available as a function and a filter. For the latter case, lhs is automatically specified as the left hand side of the filter.

# Returns "hello-world"
{{ "Hello, World!" | slugify }}

# Returns "hello_world"
{{ slugify("Hello, World!", separator="_") }}
jinjazzle.ext.string.random_string(length, punctuation=False, lowercase=True, uppercase=True, digits=True)

Return a random string of length characters from the character sets selected.

Uses secrets.choice() module to generate random strings.

Parameters:
{{ random_string(8, punctuation=True) }}