Forum


Replies: 2   Views: 846
Replace variable with page number as merge field
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 ceff  · 06-07-2022 - 07:50

Hello,

We are trying to replace a variable inside a DOCX template with the page number of the document.
We tried the following code:

$pageNumberFragment = new WordFragment($this->docx, "defaultFooter");
$pageNumberFragment->addPageNumber();
$this->docx->replaceVariableByWordFragment([
    "pageNumber" => $pageNumberFragment
], [
    "target" => "footer",
    "type" => "inline"
]);

But the resulting DOCX does not have a merge field, ony a "1" simple text.

Is this a limitation of our phpdocx version, or are we doing something wrong?
We have the advanced license for 7.5.

Thank you in advance.