with {% include 'blah.html' %} $code = preg_replace('##', "{% INCLUDE$1 '$2' %}", $code); // This strips the $ inside of a tag directly after the token, which was used in #', '', $code); // This strips the . or $ inside of a tag directly before a variable name, which was used in #', array($this, 'tag_if_cleanup'), $code); // Replace all of our starting tokens, with Twig style, {% TOKEN %} // This also strips outer parenthesis, becomes $code = preg_replace('##', '{% $1 $2 %}', $code); // Replace all of our variables, {VARNAME} or {$VARNAME}, with Twig style, {{ VARNAME }} $code = preg_replace('#{\$?([a-zA-Z0-9_\.]+)}#', '{{ $1 }}', $code); return parent::tokenize($code, $filename); } /** * preg_replace_callback to clean up IF statements * * This strips the . or $ inside of a tag directly before a variable name. * Was used in '; } }