at_least¶
The at_least filter ensures that a numeric value is not less than a specified minimum value. It is useful for setting lower bounds or default values in your Experience Builder templates.
Functionality
- Numbers: Takes a numerical value as input (integer or floating-point).
- Minimum Value: Requires a numerical argument specifying the minimum allowed value.
- Comparison: Compares the input number to the minimum value.
- Output:
- If the input number is greater than or equal to the minimum value, it returns the input number unchanged.
- If the input number is less than the minimum value, it returns the minimum value.
Syntax
Arguments
- minimum_value: The lowest acceptable numerical value. If the input number is below this value, the filter will output this
minimum_value.
Code Samples
Example 1: Ensuring a Minimum Price
{% assign product_price = 8 %}
{% assign min_price = 10 %}
{{ product_price | at_least: min_price }}
Output:
Example 2: Setting a Default Quantity {% assign quantity = 0 %}
{% assign default_quantity = 1 %}
{{ quantity | at_least: default_quantity }}
Output:
Example 3: No Change if Above Minimum Output:Outliers and Special Cases¶
- Non-Numeric Input: If the input is not a number (e.g., a string or boolean), the
at_leastfilter might attempt to convert it to a number before comparison. If the conversion fails, an error might be thrown. - Minimum Value as String: If the
minimum_valueargument is provided as a string, it needs to be convertible to a number for the comparison to work correctly.
Key Points¶
- The
at_leastfilter provides a simple way to enforce lower limits on numerical values in your templates. - It is particularly useful for scenarios where you want to guarantee that a value doesn't fall below a certain threshold.
- Use it to set default values or to cap the lower end of a range of values.
- Be mindful of data types to ensure correct behavior and avoid errors.