mirror of
https://github.com/spring-projects/spring-framework.git
synced 2026-05-04 05:17:15 +01:00
9c78f84915
Closes gh-35450
38 lines
1.1 KiB
Plaintext
38 lines
1.1 KiB
Plaintext
[[mvc-view-groovymarkup]]
|
|
= Groovy Markup
|
|
|
|
The https://groovy-lang.org/templating.html#_the_markuptemplateengine[Groovy Markup Template Engine]
|
|
is primarily aimed at generating XML-like markup (XML, XHTML, HTML5, and others), but you can
|
|
use it to generate any text-based content. The Spring Framework has a built-in
|
|
integration for using Spring MVC with Groovy Markup.
|
|
|
|
NOTE: The Groovy Markup Template engine requires Groovy 2.3.1+.
|
|
|
|
|
|
[[mvc-view-groovymarkup-configuration]]
|
|
== Configuration
|
|
|
|
The following example shows how to configure the Groovy Markup Template Engine:
|
|
|
|
include-code::./WebConfiguration[tag=snippet,indent=0]
|
|
|
|
[[mvc-view-groovymarkup-example]]
|
|
== Example
|
|
|
|
Unlike traditional template engines, Groovy Markup relies on a DSL that uses a builder
|
|
syntax. The following example shows a sample template for an HTML page:
|
|
|
|
[source,groovy,indent=0,subs="verbatim,quotes"]
|
|
----
|
|
yieldUnescaped '<!DOCTYPE html>'
|
|
html(lang:'en') {
|
|
head {
|
|
meta('http-equiv':'"Content-Type" content="text/html; charset=utf-8"')
|
|
title('My page')
|
|
}
|
|
body {
|
|
p('This is an example of HTML contents')
|
|
}
|
|
}
|
|
----
|