Partial rendering
Partial rendering is done by specifying the Thymeleaf fragment name in the _partial request parameter.
If you want to render a single ViewElement
, you should specify the ViewElement
name prefixed with ::.
If a partial fragment is specified, the entire WebTemplateProcessor
will be skipped, only the target view will be rendered.
All other controller code will still be executed, all markup will still be built, but only the markup of the selected elements will be written to the response.
Assume we create a single ViewElement
with a specific name.
@GetMapping("/render")
String get() {
model.addAttribute( "myViewElement", new TextViewElement( "myViewElement", "some text" ) );
}
And we render it in the following snippet:
<h1>title</h1>
<div th:fragment="mycontent">
<across:view element="${myViewElement}" />
</div>
-
/render would output <h1>title</h1><div>some text</div>
-
/render?_partial=mycontent would output <div>some text</div>
-
/render?_partial=::myViewElement would output some text
-
/render?_partial=mycontent::myViewElement would also output some text