Forum


Replies: 5   Views: 3890
Clone block and replace content
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 AurelienC  · 03-08-2018 - 13:16

Hello,

I am trying to achieve quite the same thing whitout success.

I have a basic template file :

$BLOCK_EXAMPLE$

Some not dynamic content.

Some dynamic content : $dynamic$

---

$BLOCK_EXAMPLE$

The cloning part works fine :

$datas = [];

for ($i=0;$i<5;$i++) {
    $docx->cloneBlock('EXAMPLE');
    $datas[] = 'number' . $i;
}

But the part where I try to populate all the differents $dynamic$ var with $datas doesn't :

foreach ($datas as $key => $item) {
    $docx->replaceVariableByHtml('dynamic', 'block', $item);
}

I end up with :

Some not dynamic content.

Some dynamic content : number0

---

(...)

---
Some not dynamic content.

Some dynamic content : number0

---

I don't know what I'm doing wrong.

And I couldn't find any example with blocks having dynamic content inside in them. I've only find examples with blocks and static content inside.

Thanks for your help.