Forum


Replies: 8   Views: 1728
Include heading item number in cross reference
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 admin  · 03-04-2020 - 08:56

Hello,

It's not possible to accomplish that task using the current version of addCrossReference. We move the request to the dev team to add support.

As the dev team sent to your email the latest version of addCrossReference that supports REF and ABOVE_BELOW, maybe you could add the following change to be able to set custom modifiers:

/**
 * Adds a cross reference
 *
 * @access public
 * @param string $text Text of the reference
 * @param array $options
 *  Values:
 * 'type' (bookmark, heading)
 * 'modifiers' (string) custom modifiers: \r \h, \n \h...
 * 'referenceName' (string) the name of the element to be referred
 * 'referenceTo' (string) content to display when the field is updated PAGEREF (default), REF, ABOVE_BELOW
 * For other options @see addText
 */
public function addCrossReference($text, $options = array())
{
    if (!isset($options['type'])) {
        $options['type'] = 'bookmark';
    }
    if (!isset($options['referenceTo'])) {
        $options['referenceTo'] = 'PAGEREF';
    }
    $modifiers = ' \h';
    if ($options['referenceTo'] == 'ABOVE_BELOW') {
        $options['referenceTo'] = 'REF';
        $modifiers = ' \p \h';
    }

    if (isset($options['modifiers'])) {
        $modifiers = $options['modifiers'];
    }

So you could set a custom modifier when adding a cross-reference:

$docx->addCrossReference('Custom text cross-reference', array('type' => 'bookmark', 'referenceName'=> 'bookmark_name', 'referenceTo' => 'REF', 'modifiers' => '\r \h'));

Maybe this small change is enough for your needs?

Regards.