简体   繁体   English

如何从Jekyll插件调用`handleize`液体过滤器?

[英]How to call the `handleize` Liquid filter from Jekyll plugin?

I must be off my game today because I can't even see where the handleize filter is even defined. 我今天必须离开我的游戏,因为我甚至看不到甚至定义了handleize过滤器的位置。 It's in the Shopify documentation , and it works when I use it in my templates. 它位于Shopify文档中 ,当我在模板中使用它时,它可以正常工作。 However I can't see the source code for it, so I can't find out how to call it from my plugin. 但是我看不到它的源代码,所以我无法找到如何从我的插件中调用它。

Also note that while these two questions are similar, the answers do not apply here because handleize is not defined in either of the source modules mentioned. 另请注意,虽然 两个问题相似,但这里的答案并不适用,因为在所提到的任何一个源模块中都没有定义handleize

If it matters, I'm using Jekyll 2.1.1 and Liquid 2.6.1. 如果重要,我使用的是Jekyll 2.1.1和Liquid 2.6.1。

对于其他任何偶然发现这一点的人, 从Jekyll版本2.4.0开始 ,你可以使用内置的slugify过滤器 ,它基本上可以执行handleize

OK turns out that the Shopify documentation is not correct; 确定Shopify文档不正确; some of the documented filters, including handleize are not available from within a standard Jekyll install. 一些文档化的过滤器,包括handleize ,在标准的Jekyll安装中不可用。 The Jekyll core team is aware of the documentation issues and is working towards fixing them. Jekyll核心团队了解文档问题,并正在努力解决这些问题。

Also note that liquid does not seem to flag any errors or warnings when using an unknown filter. 另请注意,使用未知过滤器时,液体似乎没有标记任何错误或警告。 Hence you may (as I did) think that the filter "works" when in fact it is silently being ignored. 因此,你可能(正如我所做的那样)认为过滤器“有效”,而事实上它被默默地忽略了。

这是我无法使用handleize的工作:

{{ post.title | replace: ' ', '_' }}

To also get the downcased result: 为了得到下结果:

{{ post.title | replace: ' ', '_' | downcase }}

or simply 或者干脆

{{ post.title | slugify }}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM