Skip to content

Commit ecffcd5

Browse files
committed
Let cloneBlock support search-patterns in block
Support variable like cloneRow in .docx ``` ${BLOCK} This is clone block ${NO} Name=${Name} Value=${Value} Please test it. ${/BLOCK} ``` in .php ··· $testData = array( array('Name'=>'Test Name 1', 'Value'=>123.45), array('Name'=>'Test Name 2', 'Value'=>223.45), array('Name'=>'Test Name 3', 'Value'=>323.45), array('Name'=>'Test Name End', 'Value'=>423.45), ); foreach ($testData as $n=>$v) { $templateProcessor->setValue('Name#'.($n+1), $v['Name']); $templateProcessor->setValue('Value#'.($n+1), $v['Value']); } ```
1 parent 3a58c81 commit ecffcd5

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/PhpWord/TemplateProcessor.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,8 @@ public function cloneBlock($blockname, $clones = 1, $replace = true)
256256
$xmlBlock = $matches[3];
257257
$cloned = array();
258258
for ($i = 1; $i <= $clones; $i++) {
259-
$cloned[] = $xmlBlock;
259+
$newXmlBlock = preg_replace('/\$\{(.*?)\}/', '\${\\1#' . $i . '}', $xmlBlock);
260+
$cloned[] = $newXmlBlock;
260261
}
261262

262263
if ($replace) {

0 commit comments

Comments
 (0)