Forum


Replies: 1   Views: 4539
Remove line where empty variable was
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 jamie3000  · 28-09-2016 - 15:26

Hi Guys,

I'm evaluating the software and have a quick question.

I'm sure there is an easy way to do this but I can't figure it out.

Say I have an address like so

$Address1$
$Address2$
$Address3$
$Address4$
$Address5$
$PostCode$

I'm trying to get it to remove the empty lines if address5 or address4 is an empty string. So far my code looks like the below but it doesn't seem to work.

foreach($variables as $VarToCheckRemove => $varValue)
{
      if(strlen($varValue) == 0) 
       {
            $docx->removeTemplateVariable($VarToCheckRemove, 'block');
       }
 }
        
$docx->clearBlocks();
        
$docx->replaceVariableByText($variables);

$docx->createDocxAndDownload(resource_path('letters/letter'));