Replies: 2   Views: 2681
Replacing a variable by wordfragment (pagenumber)
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 admin  · 13-06-2017 - 14:15


Sorry but we're unable to replicate the issue.

Please run this code standalone (using the classes from phpdocx without doing changes):


require_once 'classes/';

$docx = new CreateDocxFromTemplate('TemplateWordFragmentsTarget.docx');

$numbering = new WordFragment($docx);
$options = [
    'textAlign' => 'right',
    'bold' => false,
    'sz' => 14,
    'color' => '000000'
$numbering->addPageNumber('numerical', $options);

$docx->replaceVariableByWordFragment(['VAR_HEADER_3' => $numbering], ['target' => 'header']);
$docx->replaceVariableByWordFragment(['VAR_FOOTER_2' => $numbering], ['target' => 'footer']);


You may find the TemplateWordFragmentsTarget.docx in the examples/files folder. Do you get the same error?


PS we have changed your username to hide your email in the forum