Forum


Replies: 1   Views: 3607
Variables bug?
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 wizzbit  · 24-01-2012 - 11:43

I have a problem using addTemplateVariable which gives me corrupt Word documents.

After trying a few things I tried this example:

$docx = new CreateDocx();
$docx->addTemplate('../../Libraries/phpdocx_pro/examples/files/TemplateImage.docx');
print_r($docx->getTemplateVariables());
$docx->addTemplateImage('IMAGE', '../../Libraries/phpdocx_pro/examples/files/img/logo_phpdocx.gif');
$docx->createDocx('template_image');

This example works but the getTemplateVariables() gives strange results, it lists whole parts of text as a variable:
0: IMAGE
1: "/>We should first include a “placeholder” image with the properties we would like our “dynamical photo” to have: size, format, etcetera.Afterwords we should include the variable we want to parse with PHPDocX as an “alt text” for the image.If you do not know how to insert an alternative text for an image with Word the required steps are:Right click on the imageChoose “Size” from the context menuClick on the “Alternative text” tab of the popup windowFill the input text with, for example,
2: IMAGE
3: (although you may use any other variable name)In this case the PHPDocX method addTemplateImage(‘IMAGE’, ‘logo_php.gif’ ) searches for an existing image in the document with the alternative text ‘
4: IMAGE
5: ’ and replace it with logo_php.gif.In this example we will just include yet another photo of our logo .Best regards,The PHPDocX Team



I notes the same problem in another document, where I hade $HOTEL_IMAGE1$, $HOTEL_IMAGE2$ and $HOTEL_IMAGE3$
and getTemplateVariables returned:
0: HOTEL_IMAGE1
1: "/>
2: HOTEL_IMAGE2
3: "/>
4: HOTEL_IMAGE3
5: "/>

Seems like some closing XML is added as Variable somehow?



I ran check.php and everything is OK