doefom/squeeze

Squeeze 是一个 Statamic 插件,提供了一个名为 squeeze 的修饰符,通过将其替换为空字符串来从给定的字符串中删除大量字符。

0.2.0 2023-02-24 17:58 UTC

This package is auto-updated.

Last update: 2024-09-24 21:16:06 UTC


README

Squeeze 是一个 Statamic 插件,提供了一个名为 squeeze 的修饰符,通过将其替换为空字符串来从给定的字符串中删除大量字符。

功能

此插件默认删除以下字符

  • _
  • -
  • /
  • :
  • (空格)

安装方法

您可以在 Statamic 控制面板的 工具 > 插件 部分搜索此插件,然后点击 安装,或者从项目根目录运行以下命令

composer require doefom/squeeze

使用方法

在您的 .yaml 文件中,您可能有一些类似这样的字符串变量

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

然后您可以在 antlers 视图中使用修饰符,如下所示

{{ text | squeeze }}

输出如下

Astringtotestthesqueeze

选项

您也可以将自定义的可压缩字符串传递给修饰符,如下所示

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

重要提示

还可以压缩空格,但它们不能是可压缩字符串的最后一个字符

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

另外,如果您想压缩反斜杠,您需要将其转义

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