|
1 | 1 | --- |
2 | | -title: Blog |
3 | | ---- |
| 2 | +title: Listings (e.g., blog) |
| 3 | +listing: |
| 4 | + - id: links |
| 5 | + contents: links_real.yml |
| 6 | + template: links.ejs |
| 7 | +--- |
| 8 | + |
| 9 | +A [listing](https://quarto.org/docs/reference/projects/websites.html#listings) is a Quarto feature that automatically builds a list or grid of items for you. |
| 10 | + |
| 11 | +There are two ways to use listings: |
| 12 | + |
| 13 | +1. To show a list of **pages from your site** (e.g., a blog index listing all your posts). |
| 14 | +2. To show a list of **external things** (e.g., interesting projects or resources you link out to). |
| 15 | + |
| 16 | +## Listing of pages |
| 17 | + |
| 18 | +## Listing of external things |
| 19 | + |
| 20 | +**Note:** This is more advanced. The approach is based on `quarto-dev/quarto-web`'s gallery ([link](https://github.com/quarto-dev/quarto-web/blob/main/docs/gallery/gallery.ejs)). |
| 21 | + |
| 22 | +### Create a YAML file of links |
| 23 | + |
| 24 | +First, create a YAML file (e.g., `links.yml`). This contains the data for your listing page - the content your want to show, such as descriptions, links, and titles - while the page layout is handled separately by Quarto and the template below. |
| 25 | + |
| 26 | +In this example, each top-level `- category:` blcok is one section of the listing. Inside each section, the `tiles:` field contains the individual cards you want to display, and each card can have fields such as `title`, `subtitle`, `href`, and `thumbnail`. |
| 27 | + |
| 28 | +For example: |
| 29 | + |
| 30 | +```{.yaml} |
| 31 | +{{< include links.yml >}} |
| 32 | +``` |
| 33 | + |
| 34 | +### Create an EJS file |
| 35 | + |
| 36 | +Next, create an EJS template file (e.g., `links.ejs`). This file tells Quarto **how to display** the data from `links.yml`, so you can think of it as the layout or "recipe" for turning your YAML data into HTML on the page. |
| 37 | + |
| 38 | +For example: |
| 39 | + |
| 40 | +````{.txt} |
| 41 | +{{< include links.ejs >}} |
| 42 | +```` |
| 43 | + |
| 44 | +### Create the `.qmd` page |
| 45 | + |
| 46 | +Now create the Quarto page that will display the listing. This page connects the data file (`links.yml`) to the template file (`links.ejs`) and tells Quarto where the finished listing should be inserted. |
| 47 | + |
| 48 | +The `::: {#links}` div is where Quarto injects the rendered listing ofr the listing configuration with the same `id`. |
| 49 | + |
| 50 | +```{.md} |
| 51 | +--- |
| 52 | +title: Listing |
| 53 | +listing: |
| 54 | + - id: links |
| 55 | + contents: links.yml |
| 56 | + template: links.ejs |
| 57 | +--- |
| 58 | +
|
| 59 | +::: {#links} |
| 60 | +::: |
| 61 | +``` |
| 62 | + |
| 63 | +To include the page in your site, add the `.qmd` file to `_quarto.yml` |
| 64 | + |
| 65 | +### Example |
| 66 | + |
| 67 | +::: {#links} |
| 68 | +::: |
0 commit comments