Design
Aliases
Simplify Carbone tag with aliases
COMMUNITY FEATURE
Available for:
Carbone Cloud
Carbone On-premise
Embedded Carbone JS
v2.0+
Alias
Aliases can be used to simplify the maintenance of your report by avoiding repetition of code, or to insert tags where special characters such as square brackets are not allowed (for example, worksheet names).
- Write
{#... = ...}
to define an alias - Write
{$...}
to use this alias
Aliases can be defined anywhere in the document, at the end, or at the beginning. They are parsed and removed by Carbone before rendering.
Aliases do not store values. They are simply shortcuts. More information
Parametrized Alias
Aliases accept an unlimited number of parameters between parentheses, like a function in many languages. Each parameter must start by $
.
More information
An alias cannot store a value. It is just a shortcut.
If you need to store a value, use the :set formatter:
{d.products[].price:aggSum:set(c.total)}
{c.value}
Aliases are replaced by Carbone with the actual tag before processing the template. They act as a preprocessor tool (similar to #define
in C language).
For example:
Alias | Template | What Carbone Sees | Result |
---|---|---|---|
d.obj |
{d.val:mul($alias.qty)} |
{d.val:mul(d.obj.qty)} |
OK |
d.arr[i].obj |
{d.val:mul($alias.qty)} |
{d.val:mul(d.arr[i].obj.qty)} |
Not supported |
The second case is not supported because Carbone does not support starting a loop with d.arr[i].obj
inside a formatter.