Forum


Replies: 3   Views: 3267
Createtemplate.returnallvariables is not returning all variables
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 mquadrat  · 14-09-2011 - 09:20

CreateTemplate.ReturnAllVariables in some cases does not return the correct set of variables included in the document. I changed the code to the following, which works for me:

Original code:
[code]
$documentSymbol = explode(self::$_templateSymbol, self::$_document);
$i = 0;
foreach ($documentSymbol as $documentSymbolValue) {
// avoid first and last values, and tag elements
if ($i == 0 || $i == count($documentSymbol)
|| $documentSymbolValue[0] == '<') {
$i++;
continue;
} else {
$variables['document'][] = strip_tags($documentSymbolValue);
$i++;
}
}
[/code]

My code:
[code]
$documentSymbol = explode(self::$_templateSymbol, strip_tags(self::$_document));
$i = 0;
foreach ($documentSymbol as $documentSymbolValue) {
if ($i % 2 == 0) {
$i++;
continue;
} else {
$variables['document'][] = strip_tags($documentSymbolValue);
$i++;
}
}
[/code]

In the case I faced the spellchecker added xml markup directly after the delimiter, so the if-case fired and the loop continued without adding the variable. I think there was a reason you wrote the code the way you did it. So am I missing something?

Posted by admin  · 11-04-2013 - 12:13

Hello,

Thanks for the code, we'll check it.

Regards.

Posted by fonfi  · 11-04-2013 - 12:13

I am having the same issue. Some docx templates have a lot of tags, therefore the last part of following condition:
[code]
if ($i == 0 || $i == count($documentSymbol) || $documentSymbolValue[0] == '<')
[/code]

is almost always true.
I modified the code in similar way as mquadrat:
[code]
$documentSymbol = explode(self::$_templateSymbol, self::$_document);
foreach ($documentSymbol as $i => $documentSymbolValue)
{
if ($i % 2 != 0)
$variables['document'][] = strip_tags($documentSymbolValue);
}
[/code]

Please let us know what was the reason you prepared the condition in such form, so we can be sure that our modifications won't break other functionality?

I am using latest PHPDocx PRO version 2.7