Forum


Replies: 3   Views: 470
Block inside of a variable
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 uncontested  · 21-07-2023 - 03:53

Hi,

I have a template with a variable called PETBANINT. I also have a script which replace that variable into this:

All sums of cash in the possession of or subject to the sole control of ${PETNAMU}, including funds on deposit, together with accrued but unpaid interest, in banks, savings institutions, and other financial institutions, which accounts stand in ${PETNAMU}'s sole name or from which ${PETNAMU} has the sole right to withdraw funds or which are subject to ${PETNAMU}'s sole control, including the following:


${BLOCK_PETBAN}
<b>Petitioner’s Bank Account ${PETBAN-INDEX}</b>
Name of Bank or Savings Firm:           ${PETBAN-BANK-NAME}
Account Number (Last 3 Digits):         ${PETBAN-BANK-NUMBER}
${BLOCK_PETBAN}

 

After this text is inserted, I replace the variable PETNAMU successfully. The main issues come with the block... isn't working. If I put directly the same block text in the template (not the variable), it works. Also is there another issue, if I ran the "deleteBlock" it deletes all the PETBANINT, not only the block. Is there a way to solve this? 

Thanks!

 

 

Posted by admin  · 21-07-2023 - 07:27

Hello,

What block method are you using that doesn't work with your document?  Maybe you need to load the updated DOCX as a new template using CreateDocxFromTemplate?

Regarding the deleteBlock question, please note that this method removes all contents between two block variables and it includes the following option:

type

Delete type: block (default) or inline.

The block type removes paragraphs contents, and the inline type removes inline contents.

If you send to contact[at]phpdocx.com the most simple script that illustrates the code you are running we'll check it. We need to run it, so this script must use phpdocx standalone (without using external resources such as databases, web services, frameworks, CMS...). Also please attach the DOCX template you are using.

Regards.

Posted by uncontested  · 21-07-2023 - 15:29

Thanks, give me few hours and I'll prepare you a standalone sample.

Posted by admin  · 22-07-2023 - 10:23

Hello,

Although we have replied to your email, we post the same information:

  • Paragraphs are used to add contents. Block placeholders must be added in their own paragraphs to use cloneBlock. Your script is adding a single paragraph with soft line breaks.
  • Set block as type replacement when using replaceVariableByHTML. An inline replacement removes all block contents before adding them. On https://www.phpdocx.com/documentation/practical/wordfragments-and-wordml you can read more information about inline and block type replacements:

Regards.