Skip to content

Expressions

BubbleFish edited this page Apr 25, 2025 · 1 revision

Expressions

[[ <expression> ]]

Mend allows you to insert variables and do basic operations on those variables.

πŸ“¦ Context

The root. context is taken from the CLI --input attributes and is the same for all files.

The this. context is relative to the file (for the file provided in mend CLI it's the same as root.). You can set it by providing :-prefixed attributes to the block:

<pkg:example :attr1="Hello World!" :attr2="{a:'Hello' b:'World!' c:{0:'69' 1:'420'}}" />

πŸ“¦ Query

You can query nested context using <this/root>.path.to.attr. Suffix the value with ? if it's optional.

Modifiers

You can chain any number of modificators to the variable: this.attr.modifier1().modifier2().modifier3().

  • to_lower() β€” Converts the string to all lower case.
  • to_upper() β€” Converts the string to all UPPER CASE.
  • to_pascal_case() β€” Converts the string to PascalCase.
  • to_camel_case() β€” Converts the string to camelCase.
  • to_snake_case() β€” Converts the string to snake_case.
  • to_kebab_case() β€” Converts the string to kebab-case.
  • capitalize() β€” Makes the first character of the string upper case.
  • length() β€” Returns the string representation of the length of the string.
  • filename() β€” Assuming the input is a path (e.g. /some/path/to/file) returns the filename (e.g. file).
  • dir() β€” Assuming the input is a path (e.g. /some/path/to/file) returns the dir (e.g. /some/path/to).
  • extension() β€” Assuming the input is a filename (e.g. /path/to/file.html) returns the extension (e.g. .html).
  • trim_extension() β€” Assuming the input is a filename (e.g. /path/to/file.html) returns the path without extension (e.g. /path/to/file).

πŸ“¦ Operators

You can perform operations on a variable this.path.to.attr <operator> 'my value'.

Use single quotes if your value contains spaces.

  • ==, != β€” Returns true or false whether the statement is truthfull.
  • has β€” Whether the value contains the substring to the right.
  • lacks β€” Opposite of has
  • || β€” Defined a fallback. If value on the left is undefined returns the value on the right.

Note

You can only perform an operation once (e.g. this.value == 'Hello World', but not this.value == 'Hello World' == true).

The only exception is you can append || fallback (e.g. this.value == 'Hello World' || Fallback is valid).

Clone this wiki locally