// Load Twig library require_once 'vendor/autoload.php'; // Create Twig environment $twig = new Twig_Environment(new Twig_Loader_Filesystem('templates/')); // Get a stream of tokens from a template file $tokens = $twig->tokenize('my_template.html.twig');
// Get the first token of the stream $firstToken = $tokens->current();This example illustrates how to get the first token of a stream using the current method of the iterator. The token is returned as an object that contains information such as its type, value, line number and column number. Package Library: Twig Library.