Design
Smart conditional blocks
Show or hide an entire table, paragraph, ..., row with one simple Carbone tag
ENTERPRISE FEATURE
Available for:
Carbone Cloud
Carbone On-premise
Embedded Carbone JS
v4.0+
Why is it smart?
Why should you use smart conditional blocks instead of hideBegin/hideEnd
or showBegin/showEnd
or array filters?
- Shorter syntax: You only need to write one Carbone tag instead of two (Begin + End).
- Simpler to use: In some situations, it can be tricky to place hideBegin/hideEnd formatters in the document, such as when hiding a row of a table.
- Cleaner output: The targeted element is removed without leaving whitespace.
Compatible with DOCX, ODT, ODS, ODP, PDF, XLSX, and HTML documents.
A Carbone tag using :drop
or :keep
does not print anything in the generated report. The tag is removed when executed.
:drop/:keep(element)
Use the :drop
formatter to remove elements from a document if the specified condition is true.
The :keep
formatter works oppositely. It retains elements if the condition is true.
Element | Description | Accepted tag position |
---|---|---|
row |
Drop or keep a table row | In a table row |
p |
Drop or keep a paragraph | Within a paragraph |
img |
Drop or keep an image | Image title, description, or alt text |
table |
Drop or keep a table | Inside a table cell |
chart |
Drop or keep a chart | Alternative text of the chart |
shape |
Drop or keep a shape | Title, description, or alt text |
slide |
Drop or keep a slide | Inside a text box (ODP only) |
item |
Drop or keep a list item | Within a list item (ODP/ODT only) |
sheet |
Drop or keep a sheet | Inside a table cell (ODS only) |
A second parameter can be used with p
and row
to drop or keep the next N paragraphs or rows. Example:
{d.text:ifEM:drop(p, 3)}
: Drops the current paragraph and the next two paragraphs ifd.text
is empty.{d.text:ifEM:drop(row, 3)}
: Drops the current row and the next two rows ifd.text
is empty.
Known limitation:
ODS
templates only support dropping/keepingrow
andimg
.HTML
templates only support dropping/keepingtable
,row
andp
XLSX
templates only support dropping/keepingrow
Examples
Drop rows of the table if an item name contains 'Falcon':
[
{ "name": "Falcon 9" },
{ "name": "Model S" },
{ "name": "Model 3" },
{ "name": "Falcon Heavy" }
]
Planes{d[i].name}
{d[i].name:ifIN('Falcon'):drop(row)}{d[i+1].name}
PlanesModel S
Model 3
Delete the entire table if the array length is lower than 6:
[
{ "name": "Bob" }
]
Planes {d:len:ifLT(6):drop(table)}{d[i].name}
{d[i+1].name}