PHP code example of machinateur / twig-context-tags

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

    

machinateur / twig-context-tags example snippets


$environment = new \Twig\Environment(/*...*/);
$environment->addExtension(new \Machinateur\Twig\Extension\ContextTagExtension());
/** @var \Twig\Template&\Machinateur\Twig\TaggedTemplateInterface $template */
$template    = $environment->load($view)
    ->unwrap();

$tags        = $template->getContextTags();

dump($tags);

Array (
  0 => 'some-context-tag',
  1 => 'some-other-context-tag',
  2 => 'the-third-tag',
)

echo $template->render([
    // ...
]);

$tags        = $template->getContextTags(true);
// ...