mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-19 10:52:48 -07:00
document default filter
This commit is contained in:
@@ -421,6 +421,16 @@ module Liquid
|
|||||||
result.is_a?(BigDecimal) ? result.to_f : result
|
result.is_a?(BigDecimal) ? result.to_f : result
|
||||||
end
|
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 = {})
|
def default(input, default_value = '', options = {})
|
||||||
options = {} unless options.is_a?(Hash)
|
options = {} unless options.is_a?(Hash)
|
||||||
false_check = options['allow_false'] ? input.nil? : !input
|
false_check = options['allow_false'] ? input.nil? : !input
|
||||||
|
|||||||
Reference in New Issue
Block a user