Forum


Replies: 3   Views: 253
Can you add font stylings on template variable replacements?
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 daveiroquois  · 24-03-2022 - 18:06

Thanks! The code you gave for the document works fine, but not for the header for some reason. 

I looked at the documentation here: https://www.phpdocx.com/documentation/practical/wordfragments-and-wordml

$textStyles = array(
        'bold' => true,
        'color' => 'B70000'
                        );
foreach ($templateValues as $key => $value) {
        $textFragment = new WordFragment($docx, 'document');
        $textFragment->addText($value, $textStyles);
        $docx->replaceVariableByWordFragment(array($key => $textFragment), array('type' => 'inline'));
        }
$textFragment1 = new WordFragment($docx, 'firstHeader');
$textFragment1->addText('[Contract #]', $textStyles);
$docx->replaceVariableByWordFragment(array('Contract'=> $textFragment1), array('type' => 'inline'));

No errors are thrown but the header text is not replaced. Also using 'defaultHeader' doesn't work either. Please advise, thanks!