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

Update plugin to add twig functions in the way Timber 2 expects #11

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions gearlab-tools.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,12 @@
add_action('plugins_loaded', function() {
if (class_exists(Timber::class)) {
// Timber is running. Extend it!
add_filter('get_twig', function(Twig_Environment $twig) {
$twig->addFunction(new Twig_SimpleFunction(
'gearlab_paginate_links',
GearLab\paginate_links::class
));

return $twig;
add_filter('timber/twig/functions', function ($functions) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sdunham I think, you could use timber/twig filter instead and make it compatible across the board: https://timber.github.io/docs/v2/hooks/filters/#timber/twig
This would require us to check to make sure proper Twig related classes exist but it should be doable. This would be one way to ensure it will not cause issues with other older projects. Not requirement but suggestion.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great suggestion, I went ahead and implemented it. I still want to make sure any sites still using this plugin specify a version instead of a branch, and work on migrating those sites to the Sitka plugin at some point in the future, but this will provide maximum backward-compatibility. Thanks!

$functions['gearlab_paginate_links'] = [
'callable' => GearLab\paginate_links::class,
];

return $functions;
});

// Add our views/twig to Timber's list of locations.
Expand Down