Ch11: Thymeleaf Views Flashcards
Define template
Provides general structure for a web page. Editing a template modifies all pages using the template.
A template represents a ____ in MVC
view
What information does the following line in a thymeleaf template provide?
xmlns provides the syntax to IDE that will be used by the template
In a method that sends data to a template:
A ___ parameter is an object that stores the variable names and values passed into a template
model
Ex: public String methodName(Model model) {}
In a method that sends data to a template:
____ statements add data to the model object
addAttribute
Ex: model.addAttribute(“variableName”, variableValue);
In a method that sends data to a template:
___ contains the path and file name for the desired template
return string
Ex: dogs.html in animals subfolder = “animals/dogs”
Thymeleaf commands appear as ____ in standard HTML tags
attributes
The data available to a template includes variables and values stored in the ____ objects, and are accessible with by syntax ____.
model, ${variableName}
Describe the use of default text in a template
Help visualize planned layout for the webpage while under development. It improves readability, and indicates what data will appear in each section
What is th used for in the following statement:
prefix indicates beginning of a thymeleaf command
What does the following code achieve in thymeleaf?
th:each = “variableName : ${collectionName}”
Iterates through a collection. Repeats tag that contains th:each statement
${ } This syntax indicates what?
Data provided by controller/model object that is referenced by the template.
th:block is a Thymeleaf _____ which allows application of a Thymeleaf attribute to a block of code
element
Does th:block get rendered in the view?
No
List some benefits of using th:block
- helps clarify HTML code by placing related Thymeleaf attributes into separate tags
- can group together tags you want to be displayed in a given order (ex. heading/paragraph pair)
- can set up nested loops
Define fragments
Blocks of HTML elements we want to use across multiple templates
Bootstrap
Commonly used style library. Allows quick application of CSS style rules with class selectors
Write the syntax for including a conditional in Thymeleaf
th: if = “${condition}”
- Condition is boolean variable from controller or expression evaluating to a boolean
When is the following attribute considered truthy?
th:if = “${condition}”
- If condition is boolean true
- If condition is nonzero # or char
- If condition is string that isn’t “false”, “off”, or “no”
- If condition is data type other than boolean, number, character, or String
Function of th:unless statement?
element is created if condition evaluates to false
Logical AND = ____
Logical OR = ____
Logical NOT = ____, ____
and
or
!, not
What are fragments?
blocks of HTML elements we want to use across multiple templates
Use of th:remove attribute?
Selectively remove elements. ex: discard wrapper tag, but not its children
Use of th:replace attribute?
Inject fragment, replacing tag where this attribute is used