Data Structure

Constants (literals)

The following types of literal quantities are supported

  1. boolean values: truefalseTrueFalse.
  2. integers: for example: -1012.
  3. floating point number: for example: 1.21.0.
  4. string: text wrapped in quotes (single quotes ' or double quotes " or inverted characters (`), note that it must be English half-width), the front and back quotes must be paired. If the inside includes the quotation marks themselves, the outer quotation marks are replaced with another kind of quotation marks. For example, Welcome to the 'Everkm' notes.
  5. lists: use [ and ] to wrap, items are separated by semicolon commas, all list items must be of the same type, end commas are allowed. For example ["abc", "efg",].

Variables

Variables are usually defined in the template context, but can also be defined in the template.

Variable types include all the literal types above, but also object types. An object is a form that includes one or more key-value pairs, where the key name must be a string, the value can be of any other type, and the items can be of different types from each other, as well as continuing to be objects, thus creating nesting.

Variables can render output in the form of {{var_name}}.

When using lists or internal elements of objects, they can be rendered by the following special operators

System global variables

  • __publish_context Context of the current template
  • __qs Query string for the current page, including the sitemap.**.qs configuration item, the page parameter overrides the configuration item with the same name.
  • __cfg cfg configuration item
  • __page_path Path to the file corresponding to the current page
  • __page_path_base Same as __page_path, but without the extension.
  • __breadcrumbs Breadcrumb navigation. The data structure is [{"caption":"", url: ""}]
  • __lang Language code set
  • __tpl_path Current template path

Dot operator

When accessing a list, the first item can be accessed using the var.0 form, with the starting number starting at 0.

When accessing an object, use the form var.key to get the contents of the specified key.

The square bracket operator

When accessing a list, use the form var[0] to access the first item.

When accessing an object, use the var["key"] form to get the contents of the specified key.

When multiple levels of nested objects need to be accessed, they can be taken out using multiple square brackets. For example: cities["zhongguo"]["hubei"]["wuhan"]. What follows the operator is called the index, which can be a valid variable in addition to a literal.

Accessing an undefined variable with the above operator will raise an error.

Expressions

The following types of expressions are supported

Mathematical operators

The Everkm Publish can use basic numeric operators, allowing only arithmetic on numbers (integers, floats) as well as numeric variables.

  • + Adds the left and right operands. For example, {{1+2}} outputs 3.
  • - Subtracts the left and right operands. For example, {{2-1}} outputs 1.
  • * Multiplies the left and right operands. For example, {{1*2}} outputs 2.
  • / Divides the left and right operands. For example, {{ 10 / 2 }} outputs 5.
  • % Dividing the left and right operands. For example, {{ 2 % 2 }} outputs 0.

Operator precedence: from lowest to highest, siblings compute the left side first.

  • +, -
  • *, /, %

Comparison operators

  • == Both sides are equal.
  • ! = Two sides are not equal
  • > Left is greater than right
  • >= The left side is greater than or equal to the right side
  • < The left side is less than the right side
  • <= The left side is less than or equal to the right side

Logical operators

  • and Logical and. Returns true if both sides are true.
  • or Logical or. Returns true if one of the two sides is true.
  • Not Logical not, inverts the operand.

The connectors

Concatenates all operands, including strings, numbers, and other identifiers (e.g., functions, macros, etc).

{{ "hello " ~ 'world' ~ `! ` }}
{{ an_ident ~ " and a string" ~ another_ident }}
{{ an_ident ~ another_ident }}

The in operator

Checks if the left operand is contained within the right operand.

{{ some_var in [1, 2, 3] }}
{{ 'index' in page.path }}
{{ an_ident not in an_obj }}