Skip to content

Commit

Permalink
thyme commit
Browse files Browse the repository at this point in the history
  • Loading branch information
tanishapatil1234 committed Dec 18, 2023
1 parent 46c3bed commit f915783
Showing 1 changed file with 93 additions and 5 deletions.
98 changes: 93 additions & 5 deletions _notebooks/2023-12-12-ThymeLeafLesson.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
"---\n",
"toc: true\n",
"comments: true\n",
"layout: post\n",
"layout: notebook\n",
"title: Spring/Thymeleaf Lesson\n",
"description: The Divorced Coders teaching Spring/Thymeleaf for Period 3 CSA\n",
"courses: { compsci: {week: 1} }\n",
"courses: { csa: {week: 18} }\n",
"type: hacks\n",
"authors: Aditya Nawandhar, Akshat Parikh, Krishiv Mahendru, Parav Salaniwal, Raymond Sheng, Rohin Sood\n",
"---"
Expand Down Expand Up @@ -318,7 +318,10 @@
"- The usage of text substitution is an act of replacing text or content within HTML elements based on values provided by the server-side application. In Thymeleaf, it's achieved using attributes like th:text or th:utext.\n",
"\n",
"\n",
"PopCorn Hack: explain what the following code is doing:"
"PopCorn Hack: explain what the following code is doing:\n",
"\n",
"\n",
"- This is a thymeleaf template that is rendering an HTML page. The text in the <span> tags is dynamically replaced with the username variable or guest. "
]
},
{
Expand Down Expand Up @@ -352,7 +355,9 @@
"\n",
"- Conditional Rendering: This feature allows displaying or hiding content based on certain conditions. Thymeleaf provides attributes like th:if and th:unless to conditionally render HTML elements.\n",
"\n",
"PopCorn Hack: explain what the following code below is doing:\n"
"PopCorn Hack: explain what the following code below is doing:\n",
"\n",
"- This thymeleaf template renders differing welcome messages based on the value of the isAdmin variable. "
]
},
{
Expand Down Expand Up @@ -415,7 +420,8 @@
"### Iteration\n",
"- Iteration: It involves looping through collections or arrays of data to render dynamic content multiple times. Thymeleaf offers the th:each attribute for iterating over collections and rendering content for each item within the collection.\n",
"\n",
"PopCorn Hack Explain What this is Doing:"
"PopCorn Hack Explain What this is Doing:\n",
"- This tempplate iterates over the elements in the items collection and renders a list containing the current elemtn in iteration. "
]
},
{
Expand Down Expand Up @@ -670,6 +676,88 @@
"## Hack\n",
"Create a Thymeleaf template to display when a 403 error occurs (Extra indicators for adding another error code)."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n",
"<img width=\"600\" alt=\"image\" src=\"https://github.com/lightkurve/lightkurve/assets/111611921/170d8b24-2530-4a01-acca-9c4f4d67de40\">\n",
"\n",
"<img width=\"600\" alt=\"image\" src=\"https://github.com/lightkurve/lightkurve/assets/111611921/199b270c-1fee-4013-aba2-0db3e0c15cf4\">\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Create your own controller hack: \n",
"> Based on what was taught in the lesson "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"vscode": {
"languageId": "java"
}
},
"outputs": [],
"source": [
"import org.springframework.stereotype.Controller;\n",
"import org.springframework.ui.Model;\n",
"import org.springframework.web.bind.annotation.GetMapping;\n",
"\n",
"@Controller\n",
"public class KanyeWestController {\n",
"\n",
" @GetMapping(\"/kanye-songs\")\n",
" public String getKanyeWestSongs(Model model) {\n",
" String songTitle = \"Stronger\";\n",
" String album = \"Graduation\";\n",
" int releaseYear = 2007;\n",
"\n",
" // Adding Kanye West song data to the Model\n",
" model.addAttribute(\"songTitle\", songTitle);\n",
" model.addAttribute(\"album\", album);\n",
" model.addAttribute(\"releaseYear\", releaseYear);\n",
"\n",
" return \"kanyeWestSongs\";\n",
" }\n",
"}\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"vscode": {
"languageId": "java"
}
},
"outputs": [],
"source": [
"<!DOCTYPE html>\n",
"<html lang=\"en\" xmlns:th=\"http://www.thymeleaf.org\">\n",
"<head>\n",
" <meta charset=\"UTF-8\">\n",
" <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n",
" <title>Kanye West Songs</title>\n",
"</head>\n",
"<body>\n",
"\n",
" <h2>Kanye West Songs</h2>\n",
"\n",
" <!-- Display Kanye West song data using Thymeleaf expressions -->\n",
" <p th:text=\"'Song Title: ' + ${songTitle}\"></p>\n",
" <p th:text=\"'Album: ' + ${album}\"></p>\n",
" <p th:text=\"'Release Year: ' + ${releaseYear}\"></p>\n",
"\n",
"</body>\n",
"</html>\n"
]
}
],
"metadata": {
Expand Down

0 comments on commit f915783

Please sign in to comment.