Skip to content

Template Syntaxis

Sergio Alejandro Ribera Costa edited this page Oct 16, 2023 · 4 revisions

Variable Syntax

The syntax of this template library is very simple, but it has some things to take into account

Once the variable is declared with the add_variable method, it will be available for rendering, the syntax for this is:

{{ variable_name }}

Not supported

{{ variable

or

variable }}

Function Syntax

On the functions side, at the moment they only support working with declared variables, the advantage they have is that they can be included recursively

Example:

{{ function(arg1, arg2, arg3) }}

Supports n arguments, and these are processed at rendering time, after parsing.

As mentioned above, it is possible to nest functions recursively, achieving behavior like this

{{ function(trim(arg1, arg2, arg3), add_u8(one, mul_u8(two, three))) }}

Builtin Functions

The library also provides default functions for certain basic operations, from mathematics to text handling, which are only available by activating certain features

Math Functions

Available with the feature default or math

Available types: u8, u16, u32, u64, u128, i8, i16, i32, i64, i128, f32, f64

  • addition: add_<type>
  • subtraction: sub_<type>
  • multiplication: mul_<type>
  • division: div_<type>

These functions are declared as follows

fn <operation>_<type>(args: &[String]) -> FuncResult

// Example
fn add_i128(args: &[String]) -> FuncResult

And they are used as follows

Hi, {{ add_i32(one, two) }}

Text Functions

Available with the feature default or text

  • Text to Case
    • toLower: requires at least one argument up to n arguments
        toLower(args: &[String]) -> FuncResult
      usage:
        {{ toLower(a, b, c) }}
      
    • toUpper: requires at least one argument up to n arguments
        toUpper(args: &[String]) -> FuncResult
      usage:
        {{ toUpper(a, b, c) }}
      
    • trim: requires at least one argument up to n arguments
        trim(args: &[String]) -> FuncResult
      usage:
        {{ trim(a, b, c) }}
      
Clone this wiki locally