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

Remove unused template variables #1868

Open
tonoslav opened this issue May 16, 2020 · 1 comment
Open

Remove unused template variables #1868

tonoslav opened this issue May 16, 2020 · 1 comment

Comments

@tonoslav
Copy link

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

I have dynamic values which are adding into templates which should replace, but sometimes there is possibility to use some variable, sometimes not, and I need them to be removed if it was not set

Describe the solution you'd like

Replace every ${anything} which was not set with $this->setValue('anything', 'something') to be replaced with empty string

Describe alternatives you've considered

It is difficult to preset all values as empty which could be used because they are pretty dynamic

Additional context

For example I have clients which might have some sub client below him (I use dots as separator)
for example
${user.name}
and
${user.subuser.name}

but that ${user.subuser.name} is only available if he is set , what is not always and than that ${user.subuser.name} is left in my word file even if it shouldn't be

This is simplified, this problem would be pretty easy solvable like this , but it is more complex , imagine it more recursive

So just to sum it up, I just need something which remove all unreplaced/unused ${anything}

@ProtestSoftware
Copy link

A solution I am currently using is to run this code after filling out the document.

foreach($templateProcessor->getVariables() as $variable){
    $templateProcessor->setValue($variable, '');
}

This will get all unused variables and set them to an empty string.

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

No branches or pull requests

2 participants