-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add default filter to standard filters #267
Conversation
This is a great feature! And your use-case above illustrates an awesome example of when it's really necessary to have. An added bonus of this feature is that you no longer have to do this: {% if first_name %}{{ first_name }}{% else %}customer{% endif %} My only concern is that default doesn't follow the "normal" Ruby pattern of falsey values (just 👍 |
Thanks, hoping some will find this useful!
Definitely a case could be made for only using the default for falsey values. The way it's implemented now basically substitutes the default anytime the value is "blank" (the logic is actually identical to Rails' |
Agreed that it'll be easy for Rails devs to catch onto. Just want to make sure front-end devs (the target audience of Liquid, if I have my history straight), will find this simple enough to use. At any rate, it was just a thought – no reason not to accept this. |
Like it. Can't believe we did not already have this. Can you add yourself to History.md please in this PR? |
Added! |
Add default filter to standard filters
👍 |
1 similar comment
👍 |
so seems like the gem on rubygems is still at 2.6.1, when will get updated to 3.0.0? I was using the default functionality.. |
Will this be implemented into Jekyll 2.0? Surprised it's not there currently. |
I believe Jekyll is still running on an old version of Liquid. |
That's a shame, Jekyll would greatly benefit from this powerfully simple feature. |
With the recent release of Jekyll 2.1.0 now using the latest Liquid 2.6.1, I thought maybe the default filter might work. It doesn't throw an error anymore, but it just produces a blank field. This was my test:
Does anyone know if the 'default' filter is confirmed in the latest Jekyll? |
What's the value of "site.baseurl" in your example? |
At first I had it in my config as
but I also omitted the line altogether and got the same result. |
Should work with an empty string... Dunno what's going on there... |
Looks like the filter did not get included in the 2.6.1 release? https://github.com/Shopify/liquid/blob/v2.6.1/lib/liquid/standardfilters.rb |
Yeah you are right |
Darn |
A copy & paste of the Liquid 'default' filter as Jekyll plugin is available in https://github.com/brunokindt/jekyll-default-filter |
We use Liquid for rendering email templates in our email marketing application. This filter allows you to specify a default value if the variable passed in is blank. I've extracted this into a gem but I'd love to see this in Liquid proper.