Skip to content

TemplateProcessor Variable Occurence while cloning blocks #2445

Open
@thomasb88

Description

@thomasb88

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions