How to hide shapes conditionally? (lines, circles, squares)
How to hide shapes conditionally
Two solutions are available:
- NEW Use the drop formatter
- Use hideBegin/hideEnd formatters
It is supported only for DOCX and ODT files.
:drop
formatter on the documentationFirst solution
Since Carbone v4.3.0
, the drop
formatter is available to delete shapes and any element from a document. Be sure to request version 4 (or higher) of Carbone:
- For the Cloud API: set the header
"carbone-version":4
- For the Cloud Studio: Click on the top-right "settings" icon > click on "version" > Select
4.X.X
.
For the following exemple, we want to drop a round shape if a value is empty.
Include the Carbone tag {d.text:ifEM:drop(shape)}
within a shape alternate text, title or description.
- the
d.text
value is a text as a string type coming from a JSON dataset - the
:ifEM
is a conditional formatter checking if the value is empty. - the
:hide(shape)
formatter is fired if the previous condition is true. The first argumentshape
is required to defined the element to hide.
Locations to insert tags for:
- LibreOffice: Click on the shape > Select the
Draw
tab > click on thedraw
button on the top left menu > Click onTitle
orDescription
> insert the tag - MS Word: Right click on the shape > click on "edit alt text" > insert the tag
Second solution
For the following exemple, we want to drop a line shape if a value is empty.
Wrap the shape anchor with a hideBegin
and hideEnd
expression.
1. Insert the drawing
A line is inserted on the ODT document.
2. Change the drawing anchor to "as character"
3. Wrap the anchor point with conditional tags
The following screenshot is based on the JSON dataset: { "value" : true }
Generates the PDF report with Carbone, and voilà 🎉
Updated on: 03/07/2025
Thank you!