Twig Comment Errors

Sometimes I can use an HTML style comment at the start of a Twig template file that works fine:

<!-- /templates/blog.html.twig -->

{% embed 'partials/base.html.twig' %}

But sometimes Grav throws an error if I do:

<!-- /templates/page.html.twig -->

{% extends 'partials/base.html.twig' %}

That give me this error:

An exception has been thrown during the rendering of a template ("Undefined offset: 0") in "partials/navigation.html.twig" at line 25. 

Are there circumstances that I can’t use such a comment?

OK, i think the thing is you are trying to put HTML (comment in this case) outside of {% block %} definitions.

It seems this is possible when using embed but not with extends. If you read the Twig docs, embed is a kind of mashup of include and extends. It seems to have more leeway on where is a valid place to put markup.

Really this is a Twig error, and although i’m pretty competent, there are still things about Twig I have to learn!

Thanks.

That’s too bad. I like to lead off partials with comments to tell me from where code is generated, especially when I’m new to a platform.

You can still use comments. Just put them in between the relevant {% block %} tags.

Yes, some days I am not as bright as on other days. :frowning: Of course!

Thanks.