Replies: 2   Views: 2011
Remove block placeholders, but not content.
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phpdocx version includes new features and improvements. Previously unsupported features may have been added to newer releases, or past issues may have been corrected.
We encourage you to download the current phpdocx version and check the Documentation available.

Posted by kobbe  · 17-05-2019 - 08:29

I have a word template with this setup.

$BLOCK_LOAN$Bla bla bla $DATE$, bla bla bla $CURRENCY$.$BLOCK_ LOAN$

Either I want to remove the whole block, this works well with $docx->deleteTemplateBlock('LOAN');

Or I want to replace the variables DATE and CURRENCY with $docx->replaceVariableByText(['DATE' => 'test', 'CURRENCY' => 'test2']); This also works well and leave me with the result: $BLOCK_LOAN$Bla bla bla test, bla bla bla test2.$BLOCK_ LOAN$ But this leaves me with the placeholders $BLOCK_LOAN$ still in the output. So I tried to remove it with $docx->clearBlocks(); But this removes the whole block. How do I remove the placeholder-text for the block, but not the content?!

I've tried to look at documentation and examples without luck.

Posted by admin  · 17-05-2019 - 08:42


clearBlocks remove placeholders doing a block replacement, so if the paragraph of the block placeholder has other contents they are removed as well.

You can use the removeTemplateVariable method to remove any placeholder by its name. Please note that the default behaviour of this method is removing the block content (this is the full paragraph), but you can set the type option as inline to do an inline remove. Please check and run the included sample in the package that illustrates both uses.


Posted by kobbe  · 17-05-2019 - 09:36

Worked perfect!! Many thanks for fast and good response! :)