PHP code example of twigwp / twig-wordpress

1. Go to this page and download the library: Download twigwp/twig-wordpress library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

twigwp / twig-wordpress example snippets


class MyModule implements TwigWp\Module\Injectable {

	public function injectInto(\Twig\Environment $twig): \Twig\Environment {
		// Do your stuffs here.

		return $twig;
	}

}

$provider = new Provider(new \Twig\Environmnet());

add_filter('twigwp.modules', function($modules)
{
	$modules['module_name'] = new MyModule();

	return $modules;
});

$modules = $provider->modules();

$twigFactory = new \TwigWp\Factory(
	new \Twig\Loader\FilesystemLoader(),
	[
        'debug' => false,
        'charset' => 'UTF-8',
        'base_template_class' => 'Twig_Template',
        'strict_variables' => false,
        'autoescape' => 'html',
        'cache' => false,
        'auto_reload' => null,
        'optimizations' => -1,
	]
);

$twig = $twigFactory->create();