I'm taking over a project that used Twig v1 and I'm migrating to v2.5 with really no knowledge of Twig until now.... so be nice :)
Please have a look and let me know if I'm missing something. I can leave out any of the filters and it works, but I want to know why it's not as is.
Here's the error message I'm seeing:
<b>Fatal error</b>: Uncaught ReflectionException: Function () does not exist in D:\xampp\htdocs\project\includes\Twig\Node\Expression\Call.php:288
Stack trace:
#0 D:\xampp\htdocs\project\includes\Twig\Node\Expression\Call.php(288): ReflectionFunction->__construct('')
#1 D:\xampp\htdocs\project\includes\Twig\Node\Expression\Call.php(23): Twig_Node_Expression_Call->reflectCallable(NULL)
#2 D:\xampp\htdocs\project\includes\Twig\Node\Expression\Filter.php(32): Twig_Node_Expression_Call->compileCallable(Object(Twig_Compiler))
#3 D:\xampp\htdocs\project\includes\Twig\Compiler.php(84): Twig_Node_Expression_Filter->compile(Object(Twig_Compiler))
#4 D:\xampp\htdocs\project\includes\Twig\Node\If.php(46): Twig_Compiler->subcompile(Object(Twig_Node_Expression_Filter))
#5 D:\xampp\htdocs\project\includes\Twig\Node.php(82): Twig_Node_If->compile(Object(Twig_Compiler))
#6 D:\xampp\htdocs\project\includes\Twig\Compiler.php(84): Twig_Node->compile(Object(Twig_Compiler))
#7 D:\xampp\htdocs\project\includes\Twig\Node\Block.php(34 in <b>D:\xampp\htdocs\project\includes\Twig\Environment.php</b> on line <b>570</b>
In the Twig environment page I see that they had filtering for PHP scripts to be included:
$twig->addFilter('is_array', new Twig_Filter_Function('is_array'));
I updated this for v2 as:
$twig->addFilter(new Twig_Filter('is_array'));
From there I see in the template where 'is_array' is applied to an attachments array:
{% if attachments|is_array %}
<div class="knowledgebasearticleattachment">{{ LANG.ATTACHMENTS }}</div>
{% for attachment in attachments %}
<div><span class="knowledgebaseattachmenticon"></span> <a href="{{ attachment_url }}{{ attachment.id }}" target="_blank">{{ attachment.name }} ({{ attachment.filesize }})</a></div>
{% endfor %}
{% endif %}
The attachment variable is defined as an array in the controller:
$q = $db->query("SELECT * FROM ".TABLE_PREFIX."attachments WHERE article_id=".$article['id']);
while($r = $db->fetch_array($q)){
$attachments[] = $r;
}
$template_vars = array();
$template_vars['attachments'] = $attachments;