JanDC/critical-css

Class 'TwigWrapper' not found

Closed this issue · 5 comments

I tried a very simple thing but i have a Class 'TwigWrapper' not found

require_once './vendor/autoload.php';
$loader = new Twig_Loader_Filesystem(__DIR__.'/templates');
	$twigEnvironment = new Twig_Environment($loader, array(
		'cache' => './cache',
		'debug' => true,
		'auto_reload' => $auto_reload,
	));
	$twigEnvironment->addExtension(new CSSFromHTMLExtractor\Twig\Extension());
 	$twigWrapper = new TwigWrapper($twigEnvironment, [new CriticalCssProcessor()]);
	$template = $twigWrapper->loadTemplate('accueil.html');
	$titre = "homepage title";
	echo $template->render(array('titre' => $titre));

Someone can help me?

JanDC commented

Hi @pioc92 ,

Did you install the library through composer?
The TwigWrapper class is a dependency of this library...

yes, i did it...

JanDC commented

Ok

Is this your full example?
Because I don't see a use statement i.e. use TwigWrapper\TwigWrapper;
Alternatively you could use the TwigWrapper directly:
$twigWrapper = new TwigWrapper\TwigWrapper($twigEnvironment, [new CriticalCssProcessor()]);

A note though. The loadtemplate method is not yet implemented on the twig wrapper.
So for now you'd have to render your template thus:

echo $twigWrapper->render('accueil.html', ['titre' => $titre])

It's ok now!
Could you put in your example to add

use TwigWrapper\TwigWrapper;
use CriticalCssProcessor\CriticalCssProcessor;

for newbie like me ;-)

Thank you

JanDC commented

Sure thing! ;)

If you have any other issues, let me know