Add MacroExists public method to TemplateProcessor.php
Describe the problem
I would like to check if a macro exists in a document in order to make a decision. For example if the macro exists, do this stuff, if it doesn't, do this other stuff.
I don't believe there is a way accomplish this at present so I have written a simple public method called macroExists for TemplateProcessor.php in the next section for this purpose - feel free to rename/modify it as you see fit (e.g. renaming to isMacro).
Describe the expected behavior
I believe adding the following simple macroExists public method to TemplateProcessor.php will suffice and appears to be working, it returns true if the macro/placeholder text is found, false otherwise:
public function macroExists($macro)
{
return ($this->findMacro($macro) >= 0) ? true : false;
}As you can see it takes advantage of the existing protected findMacro method.
I have tried to create a pull request for this but was unable.
Priority
- I want to crowdfund the feature (with @algora-io) and fund a community developer.
- I want to pay the feature and fund a maintainer for that. (Contact @Progi1984)
Source: PHPOffice/PHPWord