PHPWord template creation - Replace text on title page .docx

Ok, so I am using PHPWord to create a template. Then, using the setValue function to replace various lines in the document, it all works correctly, but I have a title page in my document and no text is replaced on that page?

Is there any way to add this functionality. Basically all that needs to happen is the replacement (setValue) to be done in the xml corresponding to the title page (title and assets) (custom xml folder?). you can see them by extracting the .docx file after changing the file extension to .zip

How I am currently creating .docx from templated.docx file:

include_once 'Sample_Header.php';

// New Word document
echo date('H:i:s') , " Create new PhpWord object" , EOL;
$phpWord = new \PhpOffice\PhpWord\PhpWord();

$document = $phpWord->loadTemplate('resources/Template_Proposal.docx');

$document->setValue('CONTACTNAME', 'John');
$document->setValue('BUSINESSNAME', 'JBS Marketing');
$document->setValue('WEBSITE', '');
$document->setValue('DATE', '07/07/2014');

$name = 'test-proposal.docx';
echo date('H:i:s'), " Write to Word2007 format", EOL;
rename($name, "results/{$name}");

echo getEndingNotes(array('Word2007' => 'docx'));
if (!CLI) {
    include_once 'Sample_Footer.php';



source to share

All Articles