timber / sugar

Some bonus functionality for Timber
GNU General Public License v2.0
45 stars 4 forks source link

Installation when Timber is installed via Composer #9

Open timknight opened 6 years ago

timknight commented 6 years ago

Are there special considerations that need to made with installing sugar when Timber is installed through Composer? Currently when installing it and trying to execute the dummy function I get an error:

Uncaught Error: Class 'Twig_Filter_Function' not found in /wp-content/plugins/sugar/timber-sugar.php

I'm loading Timber within the functions.php exactly as defined on https://timber.github.io/docs/getting-started/setup/#via-github-for-developers.

I've installed Sugar within a different instance where Timber is installed as a WordPress plugin instead and everything seems to function without any issue.

timknight commented 6 years ago

I did rework the plugin to use the following, but this won't work when Timber is installed as a WordPress library, just when it's installed via Composer.

function __construct(){
  add_filter('get_twig', function( $twig ){
    $twig->addFilter(new Twig_Filter('dummy', array(__CLASS__, 'apply_dummy_filter')));
    $twig->addFunction(new Twig_Function('dummy', array(__CLASS__, 'apply_dummy')));

    $twig->addFilter(new Twig_Filter('twitterify', array(__CLASS__, 'twitterify')));
    return $twig;
  });
}

Maybe there's a way to get it to work with both, but either way for those in a similar situation that'll work.