问题
I must be off my game today because I can't even see where the handleize
filter is even defined. It's in the Shopify documentation, and it works when I use it in my templates. 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.
If it matters, I'm using Jekyll 2.1.1 and Liquid 2.6.1.
回答1:
For anyone else who stumbles across this, from Jekyll version 2.4.0 onward, you can use the built-in slugify filter, which basically does what handleize
does.
回答2:
OK turns out that the Shopify documentation is not correct; some of the documented filters, including handleize
are not available from within a standard Jekyll install. The Jekyll core team is aware of the documentation issues and is working towards fixing them.
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.
回答3:
Here's my work around for not being able to use handleize:
{{ post.title | replace: ' ', '_' }}
回答4:
To also get the downcased result:
{{ post.title | replace: ' ', '_' | downcase }}
or simply
{{ post.title | slugify }}
来源:https://stackoverflow.com/questions/24769572/how-to-call-the-handleize-liquid-filter-from-jekyll-plugin