Forum


Replies: 2   Views: 373
Adding lists using cloneblock
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 uncontested  · 23-11-2023 - 01:35

Hi, 

I'm trying to add a custom list style inside of a block element. This is my word document:

${LIST}

${BLOCK_SAMPLE}
${CONTENT}
${BLOCK_SAMPLE}

And then here is the code:

<?php

require_once '../../vendor/adm/phpdocx/src/Phpdocx/Create/CreateDocx.php';

$docx = new Phpdocx\Create\CreateDocxFromTemplate('document-2.docx');

$docx->setTemplateSymbol('${', '}');
$docx->createListStyle('latin', [
        ['type' => 'decimal',                'format' => '%1.'],
        ['type' => 'lowerLetter',    'format' => '%2.'],
        ['type' => 'lowerRoman',     'format' => '%3.'],
]);


$list = '<ul class="latin"><li><b>Item 1</b></li><li><b>Item 2</b></li></ul>';
$docx->replaceVariableByHTML('LIST', 'block', $list, ['customListStyles' => true]);


$word = new \Phpdocx\Elements\WordFragment($docx);
$word->createListStyle('latin', [
        ['type' => 'decimal',                'format' => '%1.'],
        ['type' => 'lowerLetter',    'format' => '%2.'],
        ['type' => 'lowerRoman',     'format' => '%3.'],
]);
$word->embedHTML($list, ['customListStyles' => true]);


$vars = [
        ['CONTENT' => 'Hello World 1'],
        ['CONTENT' => $word],
];


// clone block setting the variables to be replaced
$docx->cloneBlock('SAMPLE', 1, $vars, array('removeBlockPlaceholder' => true));

// delete remaining block
$docx->deleteTemplateBlock('SAMPLE');

$name = 'docs/output-'.rand();
$docx->createDocx($name);

header("Location: /word/".$name.".docx");

Unfortunately looks there something wrong. The first list looks good, but the one inside of the block is being rendered by ignoring the <li> tags. I tried adding the createListStyle in the word fragment but no luck. Here is the result:

----------------

  • Item 1
  • Item 2

Hello World 1

Item 1Item 2

----------------

Do you have any suggestion?

Thanks!