Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TemplateProcessor Variable Occurence while cloning blocks #2445

Open
thomasb88 opened this issue Aug 26, 2023 · 0 comments
Open

TemplateProcessor Variable Occurence while cloning blocks #2445

thomasb88 opened this issue Aug 26, 2023 · 0 comments

Comments

@thomasb88
Copy link

Is your feature request related to a problem? Please describe.

getVariableCount is hardly reliable when some blocks are cloned. The count before cloning is good, but it's possible not to apply the cloning the same way in all the differents parts.

Describe the solution you'd like

For variable count, use
public function getVariablesOccurences(){
$occurences = array('header' => array(), 'body' => 0, 'footer' => array());
$variables = $this->getVariablesForPart($this->tempDocumentMainPart);
$occurences['body'] = array_count_values($variables);
foreach ($this->tempDocumentHeaders as $header_index => $headerXML) {
$variables = $this->getVariablesForPart($headerXML);
$occurences['header'][$header_index] = array_count_values($variables);
}
foreach ($this->tempDocumentFooters as $footer_index => $footerXML) {
$variables = $this->getVariablesForPart($footerXML);
$occurences['footer'][$footer_index] = array_count_values($variables);
}

    return $occurences;
}

Then modify getVariables to have the list of the variable and no more.

public function getVariables() {
$variables = $this->getVariablesForPart($this->tempDocumentMainPart);
foreach ($this->tempDocumentHeaders as $header_index => $headerXML) {
$variables = array_merge($variables, $this->getVariablesForPart($headerXML));
}
foreach ($this->tempDocumentFooters as $footer_index => $footerXML) {
$variables = array_merge($variables, $this->getVariablesForPart($footerXML));
}
return array_unique($variables);
}

Describe alternatives you've considered

Much PHP to write, and assumptions to the template content to be made.

Additional context

My goal is to define the way the template is filled from the template itself, and not from any PHP code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

1 participant