PHP code example of rmp-up / wp-twig

1. Go to this page and download the library: Download rmp-up/wp-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/ */

    

rmp-up / wp-twig example snippets




wp_twig_register();



add_filter(
    'init',
    static function () {
        global $wp_query;
  
        $wp_query->query_vars['user'] = wp_get_current_user();  
    }
);



add_filter(
  'wp_twig_template_page_block_foo',
  static function ( array $context ) {
    $context['bar'] = 42;

    return $context;
  }
);



add_filter(
  'wp_twig_block_foo', // more generic than "wp_twig_template_page_block_foo" from above
  static function ( array $context ) {
    if ( ! array_key_exists( 'bar', $context ) ) {
        $context['bar'] = apply_filters( 'fetch_some_expensive_data', [] );
    }

    return $context;
  }
);