How to hide a paragraph conditionally
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](https://storage.crisp.chat/users/helpdesk/website/f355e91d7615e000/screenshot-2022-09-09-at-18420_1ii1zl.png)
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](https://storage.crisp.chat/users/helpdesk/website/f355e91d7615e000/screenshot-2022-09-09-at-18451_1e7vij.png)
Learn more about :drop formatter on the documentation
Updated on: 09/09/2022
Thank you!