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: docs/websites/website-listings-custom.qmd
+30-8Lines changed: 30 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -8,8 +8,7 @@ In addition to the 3 built in types of listings, you can also build a completely
8
8
9
9
## Listing Templates
10
10
11
-
To build a custom listing display, you create an [EJS template](https://ejs.co) that will be used to generate the HTML for a set of items that are passed to the template. EJS templates allow you to generate HTML using plain javascript, making it easy to loop through items and output their values in your custom HTML.
12
-
11
+
To build a custom listing display, you create an [EJS template](https://ejs.co) that will be used to generate the HTML for a set of items that are passed to the template. EJS templates allow you to generate HTML using plain JavaScript, making it easy to loop through items and output their values in your custom HTML.
13
12
14
13
To use a custom template, pass it in the `template` option for a listing:
15
14
@@ -26,22 +25,40 @@ listing:
26
25
template: gallery.ejs
27
26
```
28
27
29
-
A simple template for outputing a list of documents might look like:
28
+
A simple template for outputting a list of documents might look like:
When rendered, the above template will receive an array of listing items called `items`. When the contents of a listing are loaded from a list of documents, each of those items will be populated with the fields described in [Listing Fields](website-listings.qmd#listing-fields). In addition, any other fields included in a documents metadata will be passed as a property of the item, making it possible to use custom metadata in your documents and the listing display.
44
45
46
+
Because the EJS templates are processed by Quarto, the templates are intrinsically Markdown documents.
47
+
For example, if you want your listing `title` (*e.g.*, `My **bold** title`) to support Markdown formatting, you need to change the above simple template into:
48
+
49
+
````markdown
50
+
```{=html}
51
+
<ul>
52
+
<% for (const item of items) { %>
53
+
<li><a href="<%- item.path %>">
54
+
```
55
+
<%= item.title %>
56
+
```{=html}</a></li>
57
+
<% } %>
58
+
</ul>
59
+
```
60
+
````
61
+
45
62
::: {.callout-note}
46
63
47
64
Note that Quarto uses `lodash` to render the EJS templates. The `lodash` uses different syntax for HTML escaping text in templates.
@@ -71,7 +88,7 @@ listing:
71
88
72
89
could be rendered using:
73
90
74
-
````html
91
+
````markdown
75
92
```{=html}
76
93
<ul>
77
94
<% for (const item of items) { %>
@@ -134,7 +151,8 @@ By default, sorting, filtering, and pagination are disabled for custom listings
134
151
135
152
For example, we can modify the above `custom.ejs` template as follows:
136
153
137
-
``` html
154
+
````markdown
155
+
```{=html}
138
156
<ul class="list">
139
157
<% for (const item of items) { %>
140
158
<li <%= metadataAttrs(item) %>>
@@ -144,6 +162,7 @@ For example, we can modify the above `custom.ejs` template as follows:
144
162
<% } %>
145
163
</ul>
146
164
```
165
+
````
147
166
148
167
Once you have included these items in your template, you can then enable the options in your listing:
149
168
@@ -218,8 +237,10 @@ listing:
218
237
219
238
Template parameters can then be accessed in your template using `<%= templateParams.param1 %>`. For example, we can modify the above `custom.ejs` template as follows:
220
239
221
-
``` html
222
-
<h3><%= templateParams.param1 %></h3>
240
+
````markdown
241
+
### <%= templateParams.param1 %>
242
+
243
+
```{=html}
223
244
<ul class="pub-list list">
224
245
<% for (const item of items) { %>
225
246
<li <%= metadataAttrs(item) %>>
@@ -228,3 +249,4 @@ Template parameters can then be accessed in your template using `<%= templatePar
0 commit comments