XF 2.0 Adding a new template compiler function

Kirby

Well-known member
I'd like to add a new template compiler function, \XF\Template\Compiler::setFunction() seems to be able to do that.

But I can't find an easy way to call this: The classname is hardcoded in the container, \XF\Service\Template\Compile::recompile() gets the container and immediately uses it afterwards and there are also does not seem to be any code events that could be used.

Am I missing smth. obvious?

I could overwrite the container via app_setup, but that feels really hacky and isn't quite extendable.

Ideally I'd appreciate if
  • The container would use an extended class instead of hardcoding Template\Compiler
  • \XF\Template\Compiler::setFunction() and \XF\Template\Compiler::setTag() would use an extended class instead of hardcoding
  • There were code events in \XF\Template\Compiler::setDefaultFunctions() and \XF\Template\Compiler::setDefaultTags()
Edit
Nevermind, I should just read the comments :cool:

// We do not recommend trying to extend this class or the tags/functions it defines. Doing so may interfere
// with the upgrade process. If you must do so, it should not be part of an add-on. It should be done
// unconditionally via config.php. However, do so at your own peril as the worst case would potentially be
// an un-upgradeable installation.
 
Last edited:
What do you need to do that you can’t do with templater functions or filters?
 
I wanted to compile phrase titles into templates, but I've taken a different route now so touching the compiler is not necessary :)
 
Top Bottom