Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Archive

Twig Comment Errors

Started by Muut Archive 12 years ago · 4 replies · 352 views
12 years ago

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

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

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

But sometimes Grav throws an error if I do:

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

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

That give me this error:

TXT
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?

12 years ago

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!

12 years ago

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.

12 years ago

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

12 years ago

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

Thanks.

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1280 9 years ago
Archive · by Muut Archive, 9 years ago
2 888 9 years ago
Archive · by Muut Archive, 9 years ago
2 4018 9 years ago
Archive · by Muut Archive, 9 years ago
1 2893 9 years ago
Archive · by Muut Archive, 9 years ago
3 1077 9 years ago