Squeeze

Addon by doefom

Squeeze Main Screenshot

Squeeze is a Statamic addon that provides a modifier named "squeeze" which removes a bunch of characters from a given string by replacing them with an empty string.

Squeeze is a Statamic addon that provides a modifier named squeeze which removes a bunch of characters from a given string by replacing them with an empty string.

Features

This addon removes the following characters by default:

  • _
  • -
  • /
  • :
  • (whitespace)

How to Install

You can search for this addon in the Tools > Addons section of the Statamic control panel and click install, or run the following command from your project root:

composer require doefom/squeeze

How to Use

In your .yaml files you probably have some kind of string variable like this:

text: "A_string-to/test:the squeeze"

Then you can use the modifier in your antlers views like this:

{{ text | squeeze }}

Which outputs:

Astringtotestthesqueeze

Options

You may also pass your own squeezables to the modifier like so:

{{ text | squeeze:":-(" }}

Important note

It's also possible to squeeze whitespaces but they cannot be the last character of the squeezables string:

{{ text | squeeze:"-_ :(" }} // This will work
{{ text | squeeze:" -_:(" }} // This will work
{{ text | squeeze:"-_:( " }} // This will not work

Also, if you want to squeeze backslashes you'll need to escape them:

{{ text | squeeze:"\\" }} // This squeezes a backslash