Posts

Showing posts with the label operator

boolean

Boolean data is simply true or false.
Note that any data reference can be coerced into a boolean, which will be true if the data exists.

Operators

The following operators apply to the boolean data type.
boolean1 and boolean2
(Also supported with the syntax &&)
Returns a boolean which is true if both of the given booleans are true.
boolean1 or boolean2
(Also supported with the syntax ||)
Returns a boolean which is true if either of the given booleans are true.

number

Numbers are integer values. They can be used in mathematical operators.

Operators

The following operators apply to the number data type.
number1 + number2
Returns a number which is the sum of the given numbers.
number1 - number2
Returns a number which is the difference of the given numbers.
number1 * number2
Returns a number which is the product of the given numbers.
number1 / number2
Returns a number which is the division of the given numbers.
number1 <= number2
(Also supported with the syntax lte)
Returns a boolean which is true if the first number is less than or equal to the second number.
number1 >= number2
(Also supported with the syntax gte)
Returns a boolean which is true if the first number is greater than or equal to the second number.
number1 > number2
(Also supported with the syntax gt)
Returns a boolean which is true if the first number is greater than the second number.
number1 < number2
(Also supported with the syntax lt)
Returns a boolean which is true if the first number is less than the second number.
number1 % number2
Returns a number which is the first number modulo the second number.

string

Strings are quote-wrapped sequences of characters.
length: Provides the number of characters in the string.
size: Same as length.
escaped: Provides the HTML escaped equivalent of the string. This is useful when the string may represent user input, to avoid HTML injection attacks
jsEscaped: Provides the JS escaped equivalent of the string. This is useful when the string may represent user input, to avoid JS errors.
jsonEscaped: Provides the JSON escaped equivalent of the string. This is useful when the string may represent user input, to avoid JSON errors.
cssEscaped: Provides the CSS escaped equivalent of the string.

Operators

string1 == string2
(Also supported with the syntax eq)
Returns true if the first string is equal to the second (case-sensitive).
string1 contains string2
(Also supported with the syntax in)
Returns true if the first string contains the second (case-sensitive).
snippet(string, options)
Produces a short snippet from an HTML string.
options: Object specifying the snippeting options, which are:
  • links: boolean for whether to preserve anchors/links in the snippet. Defaults to true.
  • linebreaks: boolean for whether to preserve linebreaks (
    tags
    ) in the snippet. Defaults to true.
  • ellipsis: boolean for whether to append an ellipsis (…) to the end of the snippet. Defaults to true.
  • length: Number specifying the maximum length of the snippet.
Example usage
<b:eval expr='snippet(data:post.body, { length: 150, links: false, linebreaks: false })' />

object

Objects are containers, which have named values of many items of data.

Objects can be constructed inline, using a squiggly-brace syntax similar to JSON.
Example: An inline object being passed to the string snippet operator.
<b:eval expr='snippet(data:post.body, { length: 150, links: false, linebreaks: false })' />

url

URL data is a special type of string data which has some extra metadata values for converting the URL into other forms.

canonical: Provides the canonical equivalent of the given URL. A canonical version of a URL ignores the country domain, and is used to uniquely identify this page, for example when sharing a URL to facebook.
http: Ensures that the scheme of the given URL is http.
https: Ensures that the scheme of the given URL is https.

Operators

The following operators apply to the url data type. Note that these operators can also be used on an arbitrary string, provided that string represents a URL.
path(url, path)
Replaces the path component of the given url with the given path.
url: Url to replace the path of, e.g. data:blog.url. path: New path for the url.
params(url, params)
Replaces the query parameters of the given url with the given parameters.
url: Url to replace the path of, e.g. data:blog.url.
params: Object containing the new parameters for the url. e.g. { foo: "bar" } would produce ?foo=bar.

appendParams(url, params)
Appends (instead of replacing) extra query parameters for the given url.
url: Url to replace the path of, e.g. data:blog.url.
params: Object containing the extra parameters for the url. e.g. { foo: "bar" } would add ?foo=bar.

fragment(url, fragment)
Appends or replaces the given fragment for the given url (e.g. foo in my.url.com/page.html#foo)
url: Url to replace the path of, e.g. data:blog.url.
fragment: New fragment for the url. e.g. "url" would produce #foo=bar.

image

Image objects are wrappers for URLs which allow the image to be resized.

isResizable: true if the image can be resized using the resizeImage operator.
isYoutube: true if the image is a youtube thumbnail.
youtubeMaxResDefaultUrl: URL of the maxresdefault.jpg youtube thumbnail, which exists for HD youtube videos.
width: Width of the image, if specified explicitly, or null.
height: Height of the image, if specified explicitly, or null.

Operators

resizeImage(image, width [, ratio])
Resizes the given image url to the given width (and crops it to the given ratio, if present).
Note: If the image is smaller than the resize width, the image will not be stretched/upscaled.

image: Image, or url of the image, to be resized. e.g. data:post.featuredImage.
width: New width constraint for the image.
ratio (optional): New width:height ratio for the image to be cropped to.

sourceSet(image, widths [, ratio])
Produces a srcset attribute for the given image, resizing the given image to each of the given widths (and cropping them to the given ratio, if present).
Note: If the image is smaller than the resize width, the image will not be stretched/upscaled. This can be problematic when the requested size is larger than the image as the browser will scale it incorrectly.
image: Image, or url of the image, to produce a srcset for. e.g. data:post.featuredImage.
width: Array of new width constraints for the image.
ratio (optional): New width:height ratio for the image to be cropped to.

array

A collection of data values.
length: Provides the number of entries in the array.
size: Same as length.
last: The last item in the array.
first: The first item in the array.
empty: Whether the array has no items.
notEmpty: Whether the array has at least one items.
any: same as notEmpty.

Operators

The following operators apply to the array data type.
array contains item
Returns a boolean which is true if the given array contains the given item.
Example usage:
<b:if cond='[123, 456] contains data:post.id' /> [Special markup] </b:if>
array take number
(Also supported with the syntax limit)
Returns an array limited to number of the given array's items.
array skip number
(Also supported with the syntax offset)
Returns an array of the remaining items after skipping number of the given array's items.
lambda operators
Lambda operators are operators which apply a given function or condition to each item in an array.
They are applied using the syntax
array [lambda operation] (x => [function involving x])
Where:
  • x can be any variable name you like.
  • lambda operation is an operation from the list below.
  • function involving x is any expression involving x, where x is a variable representing an item in the array.
Lambda Operations
  • any: Returns a boolean for whether any item in the array returns true for the given function.
  • all: Returns a boolean for whether all the items in the array returns true for the given function.
  • none: Returns a boolean for whether none of the items in the array returns true for the given function.
  • count: Returns a number for the count of the items in the array that return true for the given function.
  • map: Returns an array of the results for applying the given function to each of the array items.
  • filter: Returns an array of the items which return true for the given function.

date

Dates are timestamp objects.
year: Number representing the year component of the date.
month: Number representing the month of the year (1 for Jan, 2 for Feb, etc).
day: Number representing the day of the month.
iso8601: ISO8601 standard formatting for the date.

Operators

format(date, format)
Formats the given date to the given format string, using the blog's selected language.
date: Date to be formatted, e.g. data:post.date
format: ICU format string for the date to be formatted to, in the blog's language. e.g. "MMM dd". Example: A custom Post timestamp byline (full example).
<b:eval expr='data:post.date format "MMM dd" ' />

message

Messages are strings that are translated to the blog's locale.
Some messages have parameters, such as a the author name, that need to be passed in using the tag.
Example message with parameters:
<b:message name='messages.byAuthor'>
<b:param name='authorName' expr:value='data:post.author.name' />
</b:message>


reader: Translates the message into the readers locale instead of the blog's locale.

locale

Locales are identifiers for a language and variant used by a blog.


name: Display name of the locale, e.g. "English".
language: Code representing the language, e.g. "en" for English.
country: The country of the language, e.g. "AU" for Australia.
variant: The variant of the language, e.g. "TH" for Thai digits when using locale th-TH-TH.
script: The script of the language, e.g. "Arab" for Arabic.
languageDirection: Either "LTR" (for left-to-right e.g. English), or "RTL" (for right-to-left e.g. Arabic).

Note that the blog's locale can be overridden using the hl parameter, e.g. ?hl=en will force English. This can be leveraged to try and support multiple languages (Example instructions).