protected function countToken($template, $type, $value = null) {
$lexer = new Twig_Lexer(new Twig_Environment());
$stream = $lexer
->tokenize($template);
$count = 0;
$tokens = array();
while (!$stream
->isEOF()) {
$token = $stream
->next();
if ($type === $token
->getType()) {
if (null === $value || $value === $token
->getValue()) {
++$count;
}
}
}
return $count;
}