Forum


Replies: 4   Views: 1611
Nested list styles
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 shady  · 21-01-2021 - 15:32

Hey,

I've ran into an issue where text inside an li doesn't align correctly when it's after another element (doesn't respect customStyles left and hanging properties).

For example:

$orderedListOptions = array();
$orderedListOptions[0]['type'] = 'decimal';
$orderedListOptions[0]['format'] = '%1.';
$orderedListOptions[0]['left'] = 500;
$orderedListOptions[0]['hanging'] = 500;
$orderedListOptions[1]['type'] = 'decimal';
$orderedListOptions[1]['format'] = '%1.%2.';
$orderedListOptions[1]['left'] = 1200;
$orderedListOptions[1]['hanging'] = 700;
$orderedListOptions[2]['type'] = 'decimal';
$orderedListOptions[2]['format'] = '%1.%2.%3.';
$orderedListOptions[2]['left'] = 2000;
$orderedListOptions[2]['hanging'] = 800;

$docx->createListStyle('customStyle', $orderedListOptions);
<ol class="customStyle">
  <li>
    <strong>this text aligns correctly together with list</strong>
    <ol>
      <li>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</li>
      <li>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</li>
    </ol>
    <strong>this text doesn't align correctly</strong>
    <ol>
      <li>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</li>
      <li>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</li>
    </ol>
  </li>
</ol>

Applying custom css that add's some sort of padding, margin, border or text-indent does nothing..

So I thought why not create another customStyle and wrap it with ul that has no bullets.

Like so:

$unOrderedListOptions = array();
$unOrderedListOptions[0]['type'] = 'none';
$unOrderedListOptions[0]['format'] = '';
$unOrderedListOptions[0]['left'] = 500;
$unOrderedListOptions[0]['hanging'] = 500;
$unOrderedListOptions[1]['type'] = 'none';
$unOrderedListOptions[1]['format'] = '';
$unOrderedListOptions[1]['left'] = 1200;
$unOrderedListOptions[1]['hanging'] = 700;
$unOrderedListOptions[2]['type'] = 'none';
$unOrderedListOptions[2]['format'] = '';
$unOrderedListOptions[2]['left'] = 2000;
$unOrderedListOptions[2]['hanging'] = 800;

$docx->createListStyle('customStyle2', $unOrderedListOptions);
<ol class="customStyle">
  <li>
    <strong>this text aligns correctly together with list</strong>
    <ol>
      <li>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</li>
      <li>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</li>
    </ol>
    <ul class="customStyle2">
      <li><strong>now this text aligns correctly but new styles are not applied and continues numbering for customStyle</strong>
      </li>
    </ul>
    <ol>
      <li>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</li>
      <li>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</li>
    </ol>
  </li>
</ol>

Is there any way to achieve what I want?

Posted by admin  · 21-01-2021 - 15:47

Hello,

What version and license of phpdocx are you using? Your username doesn't have any license tied, please send an email to contact[at]phpdocx.com with the username or email of the user that purchased the license.

Regards.

Posted by shady  · 21-01-2021 - 15:51

Right now i'm just trying out this library and checking if it meets my requirements :)

I'm using phpdocx-trial-basic-11.0

Posted by admin  · 21-01-2021 - 16:06

Hello,

MS Word doesn't allow setting some styles to inline elements, for example you can't set a margin to a run-of-text content (such as a strong tag when importing HTML). You need to use block tags, for example:

$html = '
<ol class="customStyle">
  <li>
    <strong>this text aligns correctly together with list</strong>
    <ol>
      <li>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</li>
      <li>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</li>
    </ol>
    <p style="margin-left: 50px;">
        <strong>this text doesnt align correctly</strong>
    </p>
    <ol>
      <li>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</li>
      <li>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</li>
    </ol>
  </li>
</ol>
';
$docx->embedHTML($html);

On the HTML API documentation you can find a detailed list of the tags and the supported styles when transforming HTML.

For the second approach (multiple list styles in the same list), you'd need to use override list styles. In the included sample LayoutAndGeneral/createListStyle/sample_4.php you can find a sample that illustrates how to create override list styles, that can be applied to lists created with addList and HTML contents.

Regards.

Posted by shady  · 21-01-2021 - 16:22

Alright, thanks for the info.