LearnAdvanced formsTemplates and splices

Templates and splices

Put values inside text.

A template builds text from fixed parts and values.

let port := 8080;
let label := `port ${port}`;
label;

Use templates for labels, messages, and small formatted strings. The text stays visible, and the inserted value has a clear place.

This is like writing a shipping label with one blank box for the order number.

Do not build large documents with one long template. Use smaller named pieces.

Template shape

A template keeps fixed text and inserted values together.

let port := 8080;
let label := `server:${port}`;

Use templates for messages, labels, and simple generated text. The literal text stays visible, and each inserted value has one clear slot.

Splice policy

Name inserted values before using them when the expression is more than a simple name.

let displayPort := port + 1;
let label := `next:${displayPort}`;

This makes the template about formatting, not hidden computation.