Open xplosionmind opened 2 years ago
@xplosionmind Thanks for the heads-up, I'll look into it!
@xplosionmind My hunch is that the examples in the README, which are written for Nunjucks but not labeled as such, are incompatible with how Liquid filters work.
If you convert the filter call from Nunjucks:
---
fruits:
- apple
- banana
- cherry
---
{{ fruits | find( "cherry" ) }}
to Liquid's format:
{{ fruits | find: "cherry" }}
I believe things should work as expected.
Things get a little trickier if you want to use a property-value object, since Liquid doesn't seem to accept Objects as filter arguments. Instead, you might capture
your ruleset first, pass it through a fromJson
filter, and then pass that result to the find
filter:
---
fruits:
- name: apple
color: red
sour: false
- name: banana
color: yellow
sour: false
- name: lemon
color: yellow
sour: true
---
{%- capture rules -%}
{
"property": "sour",
"value": true
}
{%- endcapture -%}
{% assign rules = rules | fromJson %}
{{ fruits | find: rules }}
This is adapted from Passing Object Arguments to Liquid Shortcodes in 11ty, which also describes how to implement the fromJson
filter.
Please let me know how it goes! If that seems to sort things out, I'll update the README to show both formats.
Thanks again!
This plugin is awesome and provides a great functionality, nevertheless it does not work…
log: