I have been facing an issue using PHPWord extension I am trying to generate a cv.docx file out of a template.docx file using Yii2 and PHPWord.
Here is my the content to be replaced in my template file:
${EXPERIENCES}
${/EXPERIENCES}
Here is the code in my php file
Settings::setZipClass(Settings::PCLZIP);
$template_document= 'template.docx';
$templateProcessor = new TemplateProcessor($template_document);
$workExperiences = [
[
'company' => 'PiRails - TechHub Connect',
'title' => 'Junior PHP-Laravel Developer',
'started_at' => 'June 2016',
'ended_at' => 'Dec 2016',
],
[
'company' => 'FreeLancer',
'title' => 'PHP, Asp.Net Full stack Developer',
'started_at' => 'Jan 2015',
'ended_at' => '',
],
[
'company' => 'FreeLancer',
'title' => 'PHP, Asp.Net Full stack Developer',
'started_at' => 'Jan 2015',
'ended_at' => '',
],
];
$phpWord = new PhpWord();
$section = $phpWord->addSection();
$table = $section->addTable();
$row = $table->addRow();
$row->addCell('title');
$row->addCell('Company');
$row->addCell('started_at');
$row->addCell('ended_at');
$templateProcessor->replaceBlock('EXPERIENCES', $table);
$templateProcessor->saveAs('cv'.'.docx');
Here is what I get instead in my output file:
${EXPERIENCES} ${/EXPERIENCES}
Now I have tried to find a solution on a bunch of links, few are as follow: https://github.com/PHPOffice/PHPWord/issues/341 https://github.com/PHPOffice/PHPWord/issues/683 https://www.bountysource.com/issues/3942663-deleteblock-replaceblock-doesn-t-work-properly
the last link says something about wrong placement of my text within xml of file but that too is not the case for me.
Any help is appreciated. Stay Blessed.