nystudio107 / craft-templatecomments

Adds a HTML comment with performance timings to demarcate `{% block %}`s and each Twig template that is included or extended.
https://nystudio107.com/
MIT License
20 stars 1 forks source link

Throwing exception with Craft 5.4.1 #46

Closed joostclevis closed 2 weeks ago

joostclevis commented 2 weeks ago

Describe the bug

When this plugin is enabled and you visit the website you get the error:

Can use "yield from" only with arrays and Traversables

To reproduce

Steps to reproduce the behaviour:

  1. Upgrade to Craft 5.4.1
  2. Visit website
  3. Error is visible
Error
Can use "yield from" only with arrays and Traversables

    1. in /var/www/html/vendor/twig/twig/src/Template.php at line 442
    433434435436437438439440441442443444445446447448449450451

            }

            // avoid RCEs when sandbox is enabled
            if (null !== $template && !$template instanceof self) {
                throw new \LogicException('A block must be a method on a \Twig\Template instance.');
            }

            if (null !== $template) {
                try {
                    yield from $template->$block($context, $blocks);
                } catch (Error $e) {
                    if (!$e->getSourceContext()) {
                        $e->setSourceContext($template->getSourceContext());
                    }

                    // this is mostly useful for \Twig\Error\LoaderError exceptions
                    // see \Twig\Error\LoaderError
                    if (-1 === $e->getTemplateLine()) {
                        $e->guess();

    2. in /var/www/html/templates/_boilerplate/_layouts/base-html-layout.twig at line 43 – [Twig\Template::yieldBlock](http://twig.sensiolabs.org/api/2.x/Twig/Template.html#method_yieldBlock)('headMeta', ['entry' => craft\elements\Entry, 'variables' => ['entry' => craft\elements\Entry], 'craft' => craft\web\twig\variables\CraftVariable, 'currentSite' => craft\models\Site, ...], ['htmlPage' => [__TwigTemplate_56ba394346b37ac1152aea0eb0690f63, 'block_htmlPage'], 'htmlTag' => [__TwigTemplate_650dfe68aec3e3ccb1410548ae912aad, 'block_htmlTag'], 'headTag' => [__TwigTemplate_56ba394346b37ac1152aea0eb0690f63, 'block_headTag'], 'headContent' => [__TwigTemplate_650dfe68aec3e3ccb1410548ae912aad, 'block_headContent'], ...])
    37383940414243444546474849

    {% endblock htmlTag %}

    {# -- Page content that should be included in the <head> -- #}
    {% block headContent %}
        {# -- Any <meta> tags that should be included in the <head> #}
        {% block headMeta %}
        {% endblock headMeta %}

        {# -- Any <link> tags that should be included in the <head> #}
        {% block headLinks %}
        {% endblock headLinks %}

        {# -- Inline JS #}

Versions

khalwat commented 2 weeks ago

This apparently only happens if you render an empty block like:

{% block content %}
{% endblock content %}

Putting some content in there fixes it. Unclear why currently, but I'll have a look.

khalwat commented 2 weeks ago

Released as 5.0.3 https://github.com/nystudio107/craft-templatecomments/releases/tag/5.0.3