diff --git a/lib/liquid/standardfilters.rb b/lib/liquid/standardfilters.rb index 0f4a110..6728e57 100644 --- a/lib/liquid/standardfilters.rb +++ b/lib/liquid/standardfilters.rb @@ -421,6 +421,16 @@ module Liquid result.is_a?(BigDecimal) ? result.to_f : result end + # Set a default value when the input is nil, false or empty + # + # Example: + # {{ product.title | default: "No Title" }} + # + # Use `allow_false` when an input should only be tested against nil or empty and not false. + # + # Example: + # {{ product.title | default: "No Title", allow_false: true }} + # def default(input, default_value = '', options = {}) options = {} unless options.is_a?(Hash) false_check = options['allow_false'] ? input.nil? : !input