Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Start a free Courses trial
to watch this video
Responding to a URI request with a String message proves that we're able to see our server response in the browser. In this video, we enhance our response with Thymeleaf, which is an HTML templating engine that allows us to combine static HTML with dynamic data, sending the result as the server response.
Introduction to HTML and CSS
teamtreehouse.com/library/introduction-to-html-and-css
Web Design Track
teamtreehouse.com/tracks/web-design
Thymeleaf Templates and XML Compliance
Thymeleaf is based on XML processing, and as such can be used to do much more than create HTML files. But this also means that, by default, HTML templates must by XML-compliant. So, some of the syntax that passes as valid HTML5 won't work in Thymeleaf without custom configuration of the templating engine in Spring.
If you want to use HTML5-style syntax instead, you'll need to do the following:
- Add a properties file at src/main/resources/application.properties
- Add the following text at the top:
spring.thymeleaf.mode = LEGACYHTML5
- In the dependencies block of build.gradle, add Neko HTML as a runtime dependency:
runtime 'net.sourceforge.nekohtml:nekohtml:1.9.22'
Now you should be able to use HTML5 instead of XML-compliant markup in your Thymeleaf templates. For example, instead of
<link rel="stylesheet" th:href="@{/app.css}"/>
You could omit the self-closing slash:
<link rel="stylesheet" th:href="@{/app.css}">
This can be a huge time saver in converting static HTML5 files from front-end designers into Thymeleaf templates.
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up