Forum


Replies: 1   Views: 1749
Wrong lists rendering
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 rapidtech  · 09-12-2019 - 13:36

I'm experiencing a problem with the list rendering. The first inner "decimal" list (2-d level) becomes "Upper Alpha" like the last inner list (2-d level). This happens with the 3-d level and so on. Basically all the styles for the first inner list are overwritten by the last ones.

<?php

$docx = new CreateDocx();

$html = '
    <style>
        .list-decimal {list-style-type: decimal;}
        .list-upper-alpha {list-style-type: upper-alpha;}
        .list-upper-roman {list-style-type: upper-roman;}
    </style>
    <ol class="list-upper-roman">
        <li>UPPER ROMAN 1
            <ol class="list-decimal">
                <li>Decimal 1</li>
                <li>Decimal 2</li>
                <li>Decimal 3</li>
            </ol>
        </li>
        <li>UPPER ROMAN 2</li>
        <li>UPPER ROMAN 3</li>
        <li>UPPER ROMAN 4
            <ol class="list-upper-alpha">
                <li>UPPER ALPHA 1
                    <ol>
                        <li>Decimal 1</li>
                        <li>Decimal 2</li>
                        <li>Decimal 3</li>
                    </ol>
                </li>
                <li>UPPER ALPHA 2</li>
                <li>UPPER ALPHA 3</li>
            </ol>
        </li>
    </ol>';
$docx->embedHTML($html);
$docx->createDocx('output');

 

Posted by admin  · 09-12-2019 - 18:03

Hello,

That kind of list styles uses overwriting level styles from MS Word, that are supported since phpdocx 9.5 (https://www.phpdocx.com/news/post/phpdocx-v9-5-release-notes/219) but only in addList and createListStyle. They'll be supported in HTML methods in the next release of phpdocx, as it's a work in progress.

Using the current version of phpdocx, the approach to be used would be adding placeholders in the positions to add the lists:

<ol class="list-upper-roman">
    <li>UPPER ROMAN 1
        $LIST_1$
    </li>
    <li>UPPER ROMAN 2</li>
    <li>UPPER ROMAN 3</li>
    <li>UPPER ROMAN 4
        $LIST_2$
    </li>
</ol>

and then use replaceVariableByWordFragment or replaceWordContent from DOCXPath to replace the placeholders with the new lists.

Regards.