I've got this code:
Twig template:
<div class="content-items-wrapper">
{% for item in home.latest_posts %}
{% include "partials/content-item.twig" with item %}
{% endfor %}
</div>
In my theme file:
$context['home']['latest_posts'] = new Timber::get_posts([
'posts_per_page' => 6,
]);
When using these line of code I get the following notice:
Warning: array_merge(): Argument #2 is not an array in //content/plugins/timber-library/vendor/twig/twig/lib/Twig/Environment.php(462) : eval()'d code on line 86
Followed by a fatal error:
Catchable fatal error: Argument 1 passed to Twig_Template::display() must be of the type array, null given, called in /content/plugins/timber-library/vendor/twig/twig/lib/Twig/Environment.php(462) : eval()'d code on line 86 and defined in //content/plugins/timber-library/vendor/twig/twig/lib/Twig/Template.php on line 401
The strange thing is: when I don't use the include in the Twig template, but just use the contents of this include directly the errors are gone. Also just putting one character (or even nothing) in the included partial gives the errors.
Also when not using Timber::get_posts()
, but just filling an array with the correct data, I don't get any errors.
But obviously both are not really wanted solutions :-)
What could this be?
PS: I've got a frontend-only version (running of gulp-twig), feeded by JSON data, which is just running fine.
Edit: fixed the example (copy/paste mistake)
Problem solved!
Changing
{% include "partials/content-item.twig" with item %}
into {% include "partials/content-item.twig" with { 'item' : item } %}
did the trick.