with {% include 'blah.html' %} $code = preg_replace('##', "{% INCLUDE$1 '$2' %}", $code); // Replace all of our starting tokens, with Twig style, {% TOKEN %} // This also strips the $ inside of a tag directly after the token, which was used in becomes $code = preg_replace('##', '{% $1 $2$4 %}', $code); // Replace all of our variables, {VARNAME} or {$VARNAME}, with Twig style, {{ VARNAME }} $code = preg_replace('#{\$?([a-zA-Z0-9_\.]+)}#', '{{ $1 }}', $code); //echo $code; //exit; return parent::tokenize($code, $filename); } }