Forum


Replies: 4   Views: 1577
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?