Forum


Replies: 1   Views: 1824
Styling <ul> lists
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 pwctechnicalsecurity  · 21-10-2019 - 20:38

Hi,

Hopefully one of the last questions. I have created a simple list like:

<ul>
  <li>item 1</li>
  <li>item 2</li>
</ul>

I tried to apply a style that was defined in my base template. As I am using the embedHTML function, I initially tried to apply a style through either a <ul> key, a <li> key or a class that I set on the <ul> element, like <ul class='xxx'>. Moreover, I explored the Premium customizeWordContent functions with the following function:

$docx->customizeWordContent(array(
    'type' => 'list'
), array(
        'pStyle' => 'ListRed',
    )
);

Neither one of those seem to help; yet I would like to apply a liststyle that I have set in my base template. Any suggestions?

Posted by admin  · 22-10-2019 - 08:11

Hello,

MS Word style can be applied to HTML lists setting the customListStyles option as true. On https://www.phpdocx.com/documentation/introduction/html-to-word-PHP you can find the following sample:

$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 subitem.</li>
</ul>';
$docx->embedHTML($html, array('customListStyles' => true));

Note that lists always include a numbering style and can also have a paragraph style; both styles can be applied to the same list. DOCXCustomizer can be very useful for this tasks, and the parseStyles method returns the information about existing styles, maybe you are not applying the correct style name/id.

As this is a very specific task, we recommend you to open a ticket (https://www.phpdocx.com/support) and attach your template. The dev team can generate a custom sample using your template.

Regards.