picocms / Pico

Pico is a stupidly simple, blazing fast, flat file CMS.
http://picocms.org/
MIT License
3.82k stars 616 forks source link

Adding a custom Twig function in Pico 2.0 #459

Closed wlabarron closed 5 years ago

wlabarron commented 5 years ago

Hello, I'm working on upgrading my site from Pico 1.0 -> 2.0 and my plugin to add a custom function has stopped working.

I understand that some of the events have changed in the plugins engine, so under which event in the new DummyPlugin should I be adding my function with $twig->addFunction($customFunction);?

I've tried changing from the old onPageRendering() to onTwigRegistered() but no luck.

PhrozenByte commented 5 years ago

It's onTwigRegistered now, see https://github.com/picocms/Pico/blob/e172dd20a1fe230d162bd918299840aa32e849d2/plugins/DummyPlugin.php#L519-L531

Don't forget about adding the API_VERSION constant, otherwise your plugin won't be recognized as Pico 2.0 plugin. See https://github.com/picocms/Pico/blob/e172dd20a1fe230d162bd918299840aa32e849d2/plugins/DummyPlugin.php#L26-L31

wlabarron commented 5 years ago

It was the API_VERSION constant that I didn't have, thank you!