-
Notifications
You must be signed in to change notification settings - Fork 9
Pipes
Pipes are used as part of the interpolation process by hyperpotamus.
In addition to the pipes already provided by Markup.js, hyperpotamus also supports the following:
optional: If the property/path does not exist, instead of throwing an error, returns the replacement value. <% missing_key | optional,N/A %>
current: Returns the current value in the specified array. The current value starts as the first value within the array and every time the iterate
action is called on the array, the index is incremented until the end is reached. <% order_ids | current %>
json: Formats the object or value as a JSON string. <% address | json %>
csv_safe: If the value includes a ,
, the value will be surrounded with "
double-quotation marks. If the value contains double-quotation marks, they will be escaped as \"
.
substr: Returns the substring of the value from the starting index for the specified length. <% tomfoolery
| substr,3,3 %>`
substring: Returns the substring of the value between the specified start and end indexes. <% tomfoolery
| substring,3,6 %>`
random: If the value is an array, the | random
pipe will select a random value from the array. If the value is a number, or a range of numbers, | random
will pick a random number from 0-MAX or from MIN-MAX. <% order_ids | random %>
or <% "6" | random %>
or <% "5-10" | random %>
now: outputs the current date/time as a value, ignoring any input values. <% | now %>
. This is one case where no value or literal needs to be passed in before the first pipe character.
string: Coerces the value to a string. <% user.is_married | string %>
join_pipe: Concatenates all values in the array using the pipe |
character as a delimiter. Because the pipe character has special meaning to Markup.js, the syntax to use a pipe character as a parameter to a regular | join
pipe is very difficult. <% values | join_pipe %>
.
add/sum: Either adds one number to another <% age | add,1 %>
, or sums up all of values in an array <% totals | sum %>
. |sum
is an alias for |add
.
minus/difference: Subtracts one value to another <% age | subtract,1 %>
, or subtracts each value in an array from the previous running total <% totals | subtract %>
.
times/product: Either multiplies one number with another <% age | times,1.3 %>
, or gives the product of all values in an array <% totals | product %>
. |product
is an alias for |times
.
divided_by: Divides one value by another, returning the un-rounded value. <% requests_per_minute | divided_by,60 %>
average: Returns the average of values in an array <% totals | average %>
.
date_format: Formats the given date according to the specified format in the local timezone. <% | now | date_format,YYYY-MM-DD %>
utc_format: Formats the given date according to the specified format in UTC. <% | now | date_format,YYYY-MM-DD %>
date_parse: Parses the date according to the specified format, assuming local timezone. <% created_at | date_parse,YYYY-MM-DD HH:mm:ss %>
utc_parse: Parses the date according to the specified format, assuming UTC. <% created_at | utc_parse,YYYY-MM-DD HH:mm:ss %>
date_add: Adds the specified number of intervals to the date. `<% created_at | date_add,minute,30 %>
date_subtract: Subtracts the specified number of intervals to the date. `<% created_at | date_add,minute,30 %>
boolean: Coerces/parses the specified value to a boolean. <% "true" | boolean %>
not: Inverts the value of a test.
hash/checksum: Calculates the checksum of the value according to the specified algorithm. <% customer_id | hash,MD5 %>
md5: Same as |hash
but specifies md5 as the algorithm.
sha1: Same as |hash
but specifies sha1 as the algorithm.
urlencode: URL encodes the value
urldecode: URL decodes the value
base64encode/b64encode: Base64 Encodes the value (using UTF-8)
base64decode: Base64 Decodes the value (using UTF-8)
resolve_url: Resolves one url relative to another. <% relative_path | resolve_url,base_url
%>
Hyperpotamus Documentation - home