Skip to content

Qute: allow user project (or build-items) to override other templates with same id #43906

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
ia3andy opened this issue Oct 16, 2024 · 13 comments · May be fixed by #47519
Open

Qute: allow user project (or build-items) to override other templates with same id #43906

ia3andy opened this issue Oct 16, 2024 · 13 comments · May be fixed by #47519
Assignees
Labels
area/qute The template engine kind/enhancement New feature or request

Comments

@ia3andy
Copy link
Contributor

ia3andy commented Oct 16, 2024

Description

Currently having templates with same id result in an exception.

It would be nice to allow overriding templates provided by extensions or libraries in the Quarkus application.

Implementation ideas

No response

@ia3andy ia3andy added the kind/enhancement New feature or request label Oct 16, 2024
@geoand geoand added area/qute The template engine and removed triage/needs-triage labels Oct 16, 2024
@mkouba mkouba changed the title Allow user project (or build-items) to override other templates with same id Qute: allow user project (or build-items) to override other templates with same id Oct 18, 2024
@mkouba
Copy link
Contributor

mkouba commented Oct 22, 2024

Hm, so what should be the rules like? A template from the root application archive overrides templates provided by dependencies/extensions?

(or build-items)

In the sense of a TemplatePathBuildItem where the template is not backed by a file?

We could assign a priority to all discovered templates (e.g. root=5, dependency/extension=3, TemplatePathBuildItem=custom value), then identify the highest priority and fail if multiple templates for the same path define this priority. But it could be quite confusing. ALso it would be a breaking change. So we have to be careful.

@ia3andy
Copy link
Contributor Author

ia3andy commented Oct 22, 2024

add a new property: quarkus.qute.fail-on-duplicates and keep it to true by default, then your priority idea seems like a good option

@mkouba
Copy link
Contributor

mkouba commented Oct 22, 2024

add a new property: quarkus.qute.fail-on-duplicates and keep it to true by default, then your priority idea seems like a good option

I don't think it's a good idea. From my exprience, non-default options are rarely used. OTOH it's a good idea to add a switch that can be used to revert the original behavior, i.e. quarkus.qute.fail-on-duplicates=false by default.

@ia3andy
Copy link
Contributor Author

ia3andy commented Jan 13, 2025

@mkouba any update on this?

@mkouba
Copy link
Contributor

mkouba commented Jan 13, 2025

I'm struggling to define the priority assignment rules. For example, I can imagine a use case where a template from src/main/resources/templates should always take precedence...

@gbourant
Copy link

There is also #41449 and #43749 which may overlap with this :-)

@ia3andy
Copy link
Contributor Author

ia3andy commented Apr 22, 2025

I'm struggling to define the priority assignment rules. For example, I can imagine a use case where a template from src/main/resources/templates should always take precedence...

That makes sense, is there an issue to achieve this? AFAIK resources on the same path are sorted depending on the build tool resolution, so it should be determinist and the src/main/resources should be the first.

@mkouba
Copy link
Contributor

mkouba commented Apr 22, 2025

I'm struggling to define the priority assignment rules. For example, I can imagine a use case where a template from src/main/resources/templates should always take precedence...

That makes sense, is there an issue to achieve this? AFAIK resources on the same path are sorted depending on the build tool resolution, so it should be determinist and the src/main/resources should be the first.

I'm not so sure this would work well in multi-module apps.

Also my original question was about a use case where a template from a build item overrides some other template. Which in some use cases might not be what a user needs 🤷 .

@ia3andy
Copy link
Contributor Author

ia3andy commented Apr 22, 2025

I would put priority, for example:

  • Classpath resources 10 (then sorted by resolution order)
  • Built item, default to 20, but can override the value
  • app src 30

@ia3andy
Copy link
Contributor Author

ia3andy commented Apr 22, 2025

For multi-module apps I think it's the same as any classpath dependency

@gbourant
Copy link

After reading all this i got an idea which is kinda relevant but does not solve the original feature request but maybe can be implemented alongside.

Instead of overwriting them maybe we can have all the templates under different "namespace".

So if template hello.html exists in mutiple projects, you can still use it with the fully qualified name (project group id + artifact id + directory + etc) + the template name.

You can already include templates that are under a different directory. {#include directory/hello.html}

@mkouba
Copy link
Contributor

mkouba commented Apr 23, 2025

I would put priority, for example:

* Classpath resources 10 (then sorted by resolution order)

* Built item, default to 20, but can override the value

* app src 30

In other words, application root has the highest priority and take precedence over templates from extensions and other dependencies, unless they're defined by a TemplatePathBuildItem (which can specify any priority).

Also add quarkus.qute.fail-on-duplicates=false that would fallback to the original behavior.

@ia3andy correct?

@ia3andy
Copy link
Contributor Author

ia3andy commented Apr 23, 2025

That sounds good to me..

@mkouba mkouba self-assigned this Apr 24, 2025
mkouba added a commit to mkouba/quarkus that referenced this issue Apr 24, 2025
mkouba added a commit to mkouba/quarkus that referenced this issue Apr 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/qute The template engine kind/enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants