Describe the bug
Contrary to the behaviour outlined in https://quarkus.io/guides/qute-reference#include_helper
attempting to include a template without specifying its extension results in an IllegalStateException: Template not found
Expected behavior
For the following template to correctly include the base template:
{#include base}
{#title}My Title{/title}
{#body}<div>My body.</div>{/body}
{/include}
Actual behavior
An IllegalStateException: Template not found is thrown.
To correctly include the base template its extension needs to be specified:
{#include base.html}
{#title}My Title{/title}
{#body}<div>My body.</div>{/body}
{/include}
Environment (please complete the following information):
uname -a or ver: Microsoft Windows [Version 10.0.18362.657]java -version: 13.0.2Additional context
If this is a limitation due to the fact that one could also include a plain text template maybe the extension of the template including the base template could be used as a sensible default?
/cc @mkouba
@fishb6nes Hm, I've added a quarkus-specific test here: https://github.com/quarkusio/quarkus/pull/7476 and it seems to work fine.
The truth is that we don't reflect the variant/extension of the template including the base, ie. we just try the suffixes from the QuteConfig.suffixes config list.
Ah I see what the issue is now. I thought of the included template as a template, not a tag. If the included template is in templates/tags/ it does indeed work correctly, however if it is a sibiling of the including template in templates/ it throws the not found exception. I'm assuming it works with the extension as specifying one overrides the default resolution from templates/tags/ and in stead considers it a relative path from tempates/?
If we want to leave it as is for now I've opened https://github.com/quarkusio/quarkus/pull/7487 to clarify. But automatically resolving from a templates/includes/ folder in stead of templates/tags/ might better convey the purpose of the templates within both folders.
If the included template is in templates/tags/ it does indeed work correctly
Now I'm really confused ;-). A template doesn't have to be located in templates/tags/ in order to be used for template inheritance. However, if you want to extend a template located in a nested directory (and it's not a tag) you'll have to use the path relative to templates/, ie. myIncludes/base if the base.html is located in templates/myIncludes/base.html.
It would be super helpful if you could share a simple reproducer app that would demonstrate the problem.
You're right that there is an inconsistency: if you declare templates/foo.html and also a tag templates/tags/foo.html, then the tag template will always take precedence. I think that we should probably add Engine.getTag() method (currently tags are handled in the same way like regular templates but the templates/tags prefix is added automatically). I'll add this to my draft PR.
Draft PR https://github.com/quarkusio/quarkus/pull/7476 updated - removed the inconsistency.
reproduce-quarkus-7472.zip
The reproducer was created with the default settings from https://code.quarkus.io/, all I added was the Qute dependency.
Running the project via mvnw quarkus:dev and accessing localhost:8080/tagsDetail it works fine, but accessing localhost:8080/detail (which depends on a base template outside of the tags folder throws an exception.
Thanks! I'll take a look asap.
So I can confirm that your reproducer fails with quarkus 1.2.1 and I've identified the problem - you're right and even the IncludeTest was wrong ;-). The problem should be fixed in my PR. It would be great if you could review/test it too.
Note that after this change the only way to use a tag as the base template would be to use the path relative to templates/, ie. something like {#include tags/base}.
Thanks for your contribution!
Awesome! I should be able to take a look tonight.