Forum


Replies: 1   Views: 934
How to apply list level override when importing html
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 admin  · 21-07-2021 - 07:07

Hello,

As you want to generate distinct sublists (restarting the sublists) in a list, you need to create new lists or apply level override. Otherwise you'll get a continuous numbering. You need to use HTML Extended, available in Premium licenses.

You can accomplish the requested task closing the li tag before each sublist and setting the depth to be applied:

$docx = new CreateDocx();

$html = '
<ul>
    <li>Countries</li>
        <ol>
            <li data-depth="1">Argentina</li>
            <li data-depth="1">Brasil</li>
            <li data-depth="1">Colombia</li>
        </ol>
    </li>
    <li>Cities</li>
        <ol>
            <li data-depth="1">Alabama</li>
            <li data-depth="1">Baltimore</li>
        </ol>
    </li>
</ul>
';
$docx->embedHTML($html, array('useHTMLExtended' => true));

Or the recommended approach, that is using a custom list style with level override options. On https://www.phpdocx.com/documentation/introduction/html-extended-to-word-PHP (List level override section) you can read more information about this task and a sample.

The following sample illustrates how to do it:

// custom options
$listOptions = array();
$listOptions[0]['type'] = 'bullet';

// override
$overrideListStyleOptions = array();
$overrideListStyleOptions[0]['type'] = 'lowerLetter';

$overrideListStyle = array();
$overrideListStyle[0] = array(
    'listOptions' => $overrideListStyleOptions,
    'name' => 'letter',
);

// create the list style with name: clist
$docx->createListStyle('clist', $listOptions, $overrideListStyle);

$html = '
<ul class="clist">
    <li>Countries
        <ol class="letter">
            <li>Argentina</li>
            <li>Brasil</li>
            <li>Colombia</li>
        </ol>
    </li>
    <li>Cities
        <ol class="letter">
            <li>Alabama</li>
            <li>Baltimore</li>
        </ol>
    </li>
</ul>';
$docx->embedHTML($html, array('customListStyles' => true, 'useHTMLExtended' => true));

Regards.