PHP code example of htmlburger / wpemerge-twig

1. Go to this page and download the library: Download htmlburger/wpemerge-twig 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/ */

    

htmlburger / wpemerge-twig example snippets


    \App::make()->bootstrap( [
        'providers' => [
            \WPEmergeTwig\View\ServiceProvider::class,
        ],
    ] );
    

[
    // Automatically replace the default view engine for WP Emerge.
    'replace_default_engine' => true,

    // Pass .php views to the default view engine.
    // replace_default_engine must be true for this to take effect.
    'proxy_php_views' => true,

    // One or more directories to search for views.
    // Defaults to the main ['views'] key of the configuration.
    'views' => [get_stylesheet_directory(), get_template_directory()],

    // Options passed directly to Twig.
    'options' => [
        // 'cache' defaults to the main ['cache']['path'] key of the configuration.
        'cache' => 'wp-content/uploads/wpemerge/cache/twig',
    ],
]

\App::make()->bootstrap( [
    // ... other WP Emerge options
    'twig' => [
        // ... other WP Emerge Twig options
        'options' => [
            // ... other Twig options
            'cache' => false,
        ],
    ],
] );

$myfilter = new Twig_Filter( 'myfilter', function( $string ) {
    return strtoupper( $string );
} );

// \App::resolve() used for brevity's sake - use a Service Provider instead.
$twig = \App::resolve( WPEMERGETWIG_VIEW_TWIG_VIEW_ENGINE_KEY );
$twig->environment()->addFilter( $myfilter );
twig
{{ 'hello world!' | myfilter }}