Clean existing blocks

phpdocx includes several methods to work with block elements. These elements allow to define regions made of one or more contents in a DOCX, which can be cleaned of placeholders, deleted and cloned.

The deleteBlock method deletes block placeholders along with the whole of the region they enclose. This functionality allows to define optional regions in a DOCX template and decide whether or not to delete them dynamically.

E.g., the code that follows replaces an existing placeholder in a document, then erases the whole region delimited by $BLOCK_CHARTS$ placeholders and finally cleans the rest of the block placeholders:

Note that to call the deleteBlock method you have to write the placeholder identifier without neither the $BLOCK_ prefix (or any other custom block prefix using setTemplateBlockSymbol) nor the final $ symbol.

Related information