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.

Learn more about :drop formatter on the documentation

First 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 argument shape is required to defined the element to hide.

Locations to insert tags for:
LibreOffice: Click on the shape > Select the Draw tab > click on the draw button on the top left menu > Click on Title or Description > insert the tag
MS Word: Right click on the shape > click on "edit alt text" > insert the tag

ODT template edited with LibreOffice

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.

Line on an ODT document

2. Change the drawing anchor to "as character"

Line anchor changed to as character

3. Wrap the anchor point with conditional tags

The following screenshot is based on the JSON dataset: { "value" : true }

Wrap the drawing with tags

Generates the PDF report with Carbone, and voilà 🎉
Was this article helpful?
Thank you!