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.
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?
Hello,
Thanks for the code, we'll check it.
Regards.
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