How to hide a paragraph conditionally

Since Carbone v4.3.0, the drop formatter is available to delete paragraphs conditionally 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 paragraph if the value is empty.
Include the marker {d.desc:ifEM:drop(p)} within a paragraph, and all the elements it comprises are also removed if the condition is validated.
the d.desc value is a description as a string type coming from a JSON dataset
the :ifEM is a conditional formatter checking if the value is empty.
the :drop(p) formatter is fired it the previous condition is true and will drop the paragraph. The first argument p is required to defined the element to drop.

On the screenshot below, the paragraph includes a title, description and an image thank to break-lines (ctrl+enter). If the description is empty, the paragraph is removed on the generated document.

DOCX template edited with MS Word, and used to generate a PDF, DOCX or ODT

The drop(p) can be used to remove tables or any element. Make sure the formatter is located in the same paragraph as the element.

DOCX template edited with MS Word

Learn more about :drop formatter on the documentation
Was this article helpful?
Thank you!