Post

Raw Template Expression

Raw Template expression constructs an object belonging to the `object:RawTemplate object type.

✍ Syntax

XML Template

` BacktickItem* Dollar* `

Here

  • BacktickItem := BacktickSafeChar| BacktickDollarsSafeChar| Dollar* interpolation
  • interpolation := ${ expression }
  • BacktickSafeChar := ^ ( ` | $ )
  • BacktickDollarsSafeChar := $+ ^ ( { | ` | $)
  • Dollar := $

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
import ballerina/io;

public function main() {

    string name = "";
    int age = 30;
    object:RawTemplate tmp = `My name is ${name}. My age is ${age}.`;

    io:println(tmp.strings);
    io:println(tmp.insertions);
}
["My name is ",". My age is ","."]
["",30]
 bal version
Ballerina 2201.6.0 (Swan Lake Update 6)
// Partial Code. Change View  to see full code.
public function main() {
    string name = "";
    int age = 30;
    object:RawTemplate tmp = `My name is ${name}. My age is ${age}.`;
}
// Highlights Only. Change View  to see full code.
object:RawTemplate tmp = `My name is ${name}. My age is ${age}.`;

Raw Template Expression Example

 January 1, 2023

Table of Content

Key Words

Raw Template Expression
 January 1, 2023

Table of Content

Key Words


Navigation

Site Settings

Site Theme

Source Code Density