Marc
Marc

Reputation: 4851

Hubspot - filter to convert text to slug format using HubL

I am developing a template for a client in Hubspot's COS and I am struggling to find a HubL filter that will convert a text/string into a slug format.

For example, I want to be able to convert This Text into this-text. My goal is to use this feature to dynamically assign a css class based on a module text field.

I am looking for an equivalent feature to WordPress' sanitize_title() function.

HubL is based on Python. I am not sure what native Python features work in HubL, but I would be open to that approach as well.

If anyone has accomplished this and has some insight it would be much appreciated.

Thanks!

Upvotes: 1

Views: 3260

Answers (1)

DerickB
DerickB

Reputation: 119

{% set var = "This Text" %}
{{ var|lower|replace(' ','-') }}

There's a space between the quotation marks in replace's first argument.

Upvotes: 2

Related Questions