Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with TemplateProcessor.php #2309

Open
Ervdu13 opened this issue Oct 7, 2022 · 2 comments
Open

Problem with TemplateProcessor.php #2309

Ervdu13 opened this issue Oct 7, 2022 · 2 comments

Comments

@Ervdu13
Copy link

Ervdu13 commented Oct 7, 2022

The functions "replaceBlock" and "deleteBlock" don't work.

in the function "replaceBlock" the preg_match isn't correct.
if I replace
'/(<?xml.)(<w:p.>${' . $blockname . '}</w:.?p>)(.)(<w:p.${/' . $blockname . '}</w:.?p>)/is'
by
'/(.((?s)<w:p\b(?:(?!<w:p\b).)?${' . $blockname . '}</w:.?p>))(.)((?s)<w:p\b(?:(?!<w:p\b).)[^$]?${/' . $blockname . '}</w:.?p>)/is'
(like in the function "cloneBlock"), the 2 functions are Ok

@FournyP
Copy link

FournyP commented Oct 10, 2022

Hello,

I think I have the same problem, when I use these functions in my code, the returned word file is corrupted.

I have try your solution @Ervdu13, the file is no more corrupted but the replace didn't replace, same comportement as a delete

Someone have a solution ?

@FournyP
Copy link

FournyP commented Oct 10, 2022

I have found a solution to avoid the problem,

cloneBlock work correctly, so if you want to delete the block, just clone it to 0 like this :

$templateProcessor->cloneBlock('myBlockName', 0, true);

And for replace, you have to put a variable into your template like this :

${myBlockName}
${myVar}
${/myBlockName}

And do this in your code :

$templateProcessor->cloneBlock('myBlockName', 1, true, false);
$templateProcessor->setValue('myVar', <Your value here>);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants