Forum


Replies: 2   Views: 380
Embedhtml ul class and word style
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 s.montanarella  · 03-09-2021 - 11:09

Hi',

I've this code:

<ul class="ullist">
<li>Text 1</li>
<li>Text 2</li>
</ul>

Inside my template I've create a paragraph/character style named "Paragraphlist".
Inside the configuration of "wordStyles", with others style, I set:

".ullist": "Paragraphlist"

When I open the generated docx the results is that the style is correctly connected but not the format. If I manually click again on the word style, format is applied as I expected.

All others styles are correctly applied.

I use version 11.

Thank you,
Federico

Posted by admin  · 03-09-2021 - 11:50

Hello,

A custom paragraph style can't be applied to ul tags. UL tags allow applying a custom list style; example Core/embedHTML/sample_2.php:

$latinListOptions = array();
$latinListOptions[0]['type'] = 'lowerLetter';
$latinListOptions[0]['format'] = '%1.';
$latinListOptions[1]['type'] = 'lowerRoman';
$latinListOptions[1]['format'] = '%1.%2.';
$docx->createListStyle('latin', $latinListOptions);

$html = '
<ul class="latin">
    <li>First item.</li>
    <li>Second item with subitems:
        <ul>
            <li>First subitem.</li>
            <li>Second subitem.</li>
        </ul>
    </li>
    <li>Third item.</li>
</ul>';
$docx->embedHTML($html, array('customListStyles' => true));

A custom paragraph style can be applied to block elements such as p and li tags, for example:

$latinListOptions = array();
$latinListOptions[0]['type'] = 'lowerLetter';
$latinListOptions[0]['format'] = '%1.';
$latinListOptions[1]['type'] = 'lowerRoman';
$latinListOptions[1]['format'] = '%1.%2.';
$docx->createListStyle('latin', $latinListOptions);

$style = array(
    'italic' => true,
    'underline' => 'dash',
);
$docx->createParagraphStyle('myParagraphStyle', $style);

$html = '
<ul class="latin">
    <li class="myParagraphStyle">First item.</li>
    <li class="myParagraphStyle">Second item with subitems:
        <ul>
            <li>First subitem.</li>
            <li>Second subitem.</li>
        </ul>
    </li>
    <li class="myParagraphStyle">Third item.</li>
</ul>
';
$docx->embedHTML($html, array('customListStyles' => true, 'wordStyles' => array('.myParagraphStyle' => 'myParagraphStyle')));

If you want to avoid adding some default styles (such as the base color) you need to use strictWordStyles or addDefaultStyles options. Otherwise these default styles will have more priority than the ones applied to the custom style.

You can also add a custom numbering style to a custom paragraph style: examples/LayoutAndGeneral/createParagraphStyle/sample_3.php

Regards.

Posted by s.montanarella  · 03-09-2021 - 12:39

Ok, so there isn't an automatic way to convert ul class to word styles as for other elements (or i misunderstood?).

I'll try to convert every li tag into a paragraph inside html.

Thank you,
Federico