Forum


Replies: 2   Views: 1243
Updating a list to match 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 pwctechnicalsecurity  · 01-04-2021 - 20:23

Hi team,

Quick question. I am looping to generate a number of documents (generally adding new content through EmbedHTML; one of the last steps is to check for all lists in my $docx. 

$docx->customizeWordContent(array(
    'type' => 'list'
), array(
        'type' => 18,
        'pStyle' => 'ListBullet',
        'lineSpacing' => 280
    )
);

Bottom line is that all lists in HTML that are declared like the following code, render perfectly to what I need.

{% if solution.sub_solutions | length > 0 %}
<ul>
    {% for sub_solution in solution.sub_solutions %}
    <li>{{ sub_solution }}</li>
    {% endfor %}
</ul>
{% endif %}

However, as soon as it is embedded in a table, it does not work (wordStyle: Normal, expected: ListBullet). Example:

<table>
    <tr>
        <td>{% if solution.sub_solutions | length > 0 %}
            <ul>
                {% for sub_solution in solution.sub_solutions %}
                <li>{{ sub_solution }}</li>
                {% endfor %}
            </ul>
            {% endif %}</td>
    </tr>
</table>

Any ideas?

Posted by admin  · 02-04-2021 - 09:31

Hello,

customizeWordContent uses w:body as default parent, so only the contents that have w:body as parent will be changed.
On the API method doc page (https://www.phpdocx.com/api-documentation/docxcustomizer/customize-docx-Word-documents-PHP), you can find explained the following option:

parent   string   Main document body as default, allows to set any parent or a specific one. w:body (default), '/' (any parent) or any other specific parent (/w:tbl/, /w:tc/, /w:r/...).

If you want to apply customizeWordContent to all contents, not only the ones that have the main w:body as parent, for example when you embed a list in a table, you can set parent to '/' (any parent), or a specific parent (for example '/w:tc/' for cells). If you don't know the specific parent, we recommend you to use the global '/' parent.

Regards.

Posted by pwctechnicalsecurity  · 02-04-2021 - 14:59

This works! Thank you for pointing us in the right direction.