Created
May 23, 2013 22:47
-
-
Save michaelhagedon/5640064 to your computer and use it in GitHub Desktop.
Test script for Drupal Twig issue: http://drupal.org/node/1922304
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| use Drupal\Core\Template\TwigReferenceFunction; | |
| use Drupal\Core\Template\TwigTemplate; | |
| use Drupal\Core\Template\TwigNodeExpressionGetAttrReference; | |
| use Drupal\Core\Template\TwigNodeExpressionNameReferenceEnd; | |
| use Drupal\Core\Template\TwigNodeExpressionNameReference; | |
| use Drupal\Core\Template\TwigReferenceNodeVisitor; | |
| function twig_change(&$context, $template, $val) { | |
| // Unwrap reference if twig_reference key is set | |
| if (isset($val['#twig_reference']) && $val['#twig_reference'] === TRUE) { | |
| $val = &$template->unwrapReference($context, $val); | |
| } | |
| // Add some key to verify the value could be modified | |
| if (is_array($val)) { | |
| $val['#printed'] = TRUE; | |
| } | |
| var_dump($val); | |
| } | |
| $twig = Drupal::service('twig'); | |
| //$loader = new Twig_Loader_String(); | |
| //$twig = new Twig_Environment($loader, array( | |
| // 'debug' => TRUE, | |
| // 'strict_variables' => FALSE, | |
| // 'autoescape' => FALSE, | |
| // 'cache' => false, | |
| // 'base_template_class' => 'Drupal\Core\Template\TwigTemplate', | |
| //)); | |
| $twig->addFunction('change', new TwigReferenceFunction('twig_change', array('needs_context' => TRUE))); | |
| $twig->addFunction('change_val', new Twig_Function_Function('twig_change', array('needs_context' => TRUE))); | |
| //$twig->addNodeVisitor(new TwigReferenceNodeVisitor()); | |
| //$twig->addExtension(new Twig_Extension_Debug()); | |
| $vars = array('x' => array('foo'), 'y' => array()); | |
| $name = 'test-twig-reference-node-visitor.html.twig'; | |
| //print $twig->parse($twig->tokenize($code)); | |
| print $twig->render($name, array('vars' => $vars)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment