You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+9-10
Original file line number
Diff line number
Diff line change
@@ -136,12 +136,12 @@ let render param =
136
136
137
137
This runs `dream_eml` on the `template.eml.html` template to generate the corresponding `template.ml` OCaml file.
138
138
139
-
The function `render` from `template.eml.html` can now be used in your program like this: `Template.render`.
139
+
The function `home` from `template.eml.html` can now be used in your program like this: `Template.home`.
140
140
141
141
3. Change `main.ml` by replacing the string "Hello world!" with
142
142
143
143
```ocaml
144
-
(Template.render "world")
144
+
(Template.home "world")
145
145
```
146
146
147
147
to use the new template.
@@ -213,9 +213,9 @@ This is, for now, a list of blog posts that have a `title`, a `slug`, a `html_bo
213
213
214
214
Now, `Post.t` is a type that represents a single blog post, and `Post.all : t list` is the list of all blog posts.
215
215
216
-
2.Rename the `render` function in `template.eml.html` to `all_posts` and change the HTML template to render a list of blog posts.
216
+
2.Change the `home` function in `template.eml.hml` to render a list of blog posts.
217
217
218
-
Instead of taking a `param` parameter, the new `all_posts` function takes a parameter `(posts: Post.t list)`.
218
+
Instead of taking `param`as parameter, the new `home` function takes a parameter `(posts: Post.t list)`.
219
219
220
220
Instead of showing `Hello <%s param %>! This is a HTML Template.`, you can iterate over the list of posts using the `List.iter` function like this:
221
221
@@ -224,6 +224,7 @@ Instead of showing `Hello <%s param %>! This is a HTML Template.`, you can itera
224
224
... TODO: write HTML here ...
225
225
<% ); %>
226
226
```
227
+
227
228
Render a `<ul>` and iterate over the list to render a `<li>` tag that contains the title of the blog post.
228
229
229
230
Hint: <%s ... %> is used to render an OCaml string.
@@ -232,9 +233,7 @@ Hint: <%s ... %> is used to render an OCaml string.
232
233
233
234
### Step 5: Subpage for individual posts
234
235
235
-
All we did in the last step was render a list of titles of the blog posts, but now we want to give every blog post its own HTML page under the URL `/post/:slug`, where `:slug` is the value of the `slug` field of the particular blog post. This would allow people to link to or bookmark a specific blog post.
236
-
237
-
We will need a new template for the
236
+
All we did in the last step was render a list of titles of the blog posts, but now we want to give every blog post its own HTML page under the URL `/post/:slug`, where `:slug` is the value of the `slug` field of the particular blog post. This will allow people to link to or bookmark a specific blog post.
238
237
239
238
**Tasks:**
240
239
@@ -276,7 +275,7 @@ match post with
276
275
277
276
to render `Template.post` when a post was found, and return a 404 response when no post with the given slug was found.
278
277
279
-
4. Modify `Template.all_posts` so that every blog post has an `<a>` tag around the title that links to the new route.
278
+
4. Modify `Template.home` so that every blog post has an `<a>` tag around the title that links to the new route.
280
279
281
280
You will need to use `<%s ... %>` again to render `post.slug` as part of the URL.
282
281
@@ -302,14 +301,14 @@ See https://aantron.github.io/dream/#static-files for an example of how to do th
302
301
303
302
3. Add a `<div class="container">` right inside the body of both templates, to wrap the existing elements.
304
303
305
-
3a. (optional) Having the basic structure / layout of the page repeated in every template is repetitive. Can you see how to move the `<html>, <head>, <link>, <body>, <div class="container">` to a separate function that can be used by both the `post` and the `all_posts` template?
304
+
3a. (optional) Having the basic structure / layout of the page repeated in every template is repetitive. Can you see how to move the `<html>, <head>, <link>, <body>, <div class="container">` to a separate function that can be used by both the `post` and the `home` template?
306
305
307
306
Hint: You can create a `layout` function that takes a string parameter `inner_html` and renders it inside the template with `<%s! inner_html %>`.
308
307
309
308
Hint 2: It is possible to pass a HTML template to the `layout` function like this:
0 commit comments