Skip to content

Commit fdbf1f6

Browse files
committed
docs: improve custom listing documentation
1 parent c71396c commit fdbf1f6

File tree

1 file changed

+30
-8
lines changed

1 file changed

+30
-8
lines changed

docs/websites/website-listings-custom.qmd

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ In addition to the 3 built in types of listings, you can also build a completely
88

99
## Listing Templates
1010

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.
1312

1413
To use a custom template, pass it in the `template` option for a listing:
1514

@@ -26,22 +25,40 @@ listing:
2625
template: gallery.ejs
2726
```
2827

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:
3029

31-
``` html
30+
````markdown
31+
```{=html}
3232
<ul>
3333
<% for (const item of items) { %>
3434
<li><a href="<%- item.path %>"><%= item.title %></a></li>
3535
<% } %>
3636
</ul>
3737
```
38+
````
3839

3940
which produces simple HTML output like:
4041

4142
![](images/listing-custom-output.png){.border}
4243

4344
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.
4445

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+
4562
::: {.callout-note}
4663

4764
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:
7188

7289
could be rendered using:
7390

74-
```` html
91+
````markdown
7592
```{=html}
7693
<ul>
7794
<% for (const item of items) { %>
@@ -134,7 +151,8 @@ By default, sorting, filtering, and pagination are disabled for custom listings
134151

135152
For example, we can modify the above `custom.ejs` template as follows:
136153

137-
``` html
154+
````markdown
155+
```{=html}
138156
<ul class="list">
139157
<% for (const item of items) { %>
140158
<li <%= metadataAttrs(item) %>>
@@ -144,6 +162,7 @@ For example, we can modify the above `custom.ejs` template as follows:
144162
<% } %>
145163
</ul>
146164
```
165+
````
147166

148167
Once you have included these items in your template, you can then enable the options in your listing:
149168

@@ -218,8 +237,10 @@ listing:
218237

219238
Template parameters can then be accessed in your template using `<%= templateParams.param1 %>`. For example, we can modify the above `custom.ejs` template as follows:
220239

221-
``` html
222-
<h3><%= templateParams.param1 %></h3>
240+
````markdown
241+
### <%= templateParams.param1 %>
242+
243+
```{=html}
223244
<ul class="pub-list list">
224245
<% for (const item of items) { %>
225246
<li <%= metadataAttrs(item) %>>
@@ -228,3 +249,4 @@ Template parameters can then be accessed in your template using `<%= templatePar
228249
<% } %>
229250
</ul>
230251
```
252+
````

0 commit comments

Comments
 (0)