Use case
In Roq (Quarkus static site generator), content files are wrapped in {#include layout}...{/include} at build time. We need content-only rendering (without layout) for features like page.content().
Using {#fragment} around the content body would let us call template.getFragment("content").render() for content-only output, while the full template.render() produces the complete page with layout. This avoids maintaining two separate templates per page.
However, for example userscould use {#head}...{/head} in content files to inject CSS/JS into the layout's <head>. When this insert override is inside a {#fragment}, parsing fails.
Problem
{#insert} overrides (like {#head}) inside a {#fragment} within {#include} fail at parse time:
Parser error: no section helper found for {#head}
The parser loses the {#include} context when entering the {#fragment}.
Reproducer
Run with jbang FragmentInsertTest.java:
///usr/bin/env jbang "$0" "$@" ; exit $?
//DEPS io.quarkus.qute:qute-core:3.34.2
import io.quarkus.qute.Engine;
import io.quarkus.qute.Template;
public class FragmentInsertTest {
public static void main(String[] args) {
Engine engine = Engine.builder().addDefaults().build();
engine.putTemplate("layout", engine.parse("""
<html>
<head>{#insert head /}</head>
<body>{#insert /}</body>
</html>"""));
// WORKS: {#head} outside fragment
Template ok = engine.parse("""
{#include layout}
{#head}<link href="extra.css">{/head}
{#fragment id=content}<h1>Hello</h1>{/fragment}
{/include}""", null, "ok.html");
System.out.println(ok.render());
System.out.println(ok.getFragment("content").render());
// FAILS: {#head} inside fragment
engine.parse("""
{#include layout}
{#fragment id=content}
{#head}<link href="extra.css">{/head}
<h1>Hello</h1>
{/fragment}
{/include}""", null, "fails.html");
}
}
To support this
{#fragment} inside {#include} should preserve the include context, allowing insert overrides within the fragment.
When used independently using getFragment("content"), they should just be stub/empty section (<h1>Hello</h1>would be the result of the content in the example above)
Environment
- Quarkus/Qute: 3.34.2, Java 21
Use case
In Roq (Quarkus static site generator), content files are wrapped in
{#include layout}...{/include}at build time. We need content-only rendering (without layout) for features likepage.content().Using
{#fragment}around the content body would let us calltemplate.getFragment("content").render()for content-only output, while the fulltemplate.render()produces the complete page with layout. This avoids maintaining two separate templates per page.However, for example userscould use
{#head}...{/head}in content files to inject CSS/JS into the layout's<head>. When this insert override is inside a{#fragment}, parsing fails.Problem
{#insert}overrides (like{#head}) inside a{#fragment}within{#include}fail at parse time:The parser loses the
{#include}context when entering the{#fragment}.Reproducer
Run with
jbang FragmentInsertTest.java:To support this
{#fragment}inside{#include}should preserve the include context, allowing insert overrides within the fragment.When used independently using
getFragment("content"), they should just be stub/empty section (<h1>Hello</h1>would be the result of the content in the example above)Environment