| 1 | --- |
| 2 | depends: |
| 3 | - guide/syntax#importing-slides |
| 4 | - features/importing-slides |
| 5 | tags: [syntax] |
| 6 | description: | |
| 7 | Merge frontmatter from multiple markdown files. |
| 8 | --- |
| 9 | |
| 10 | # Frontmatter Merging |
| 11 | |
| 12 | You can provide frontmatter instructions from both your main entry and external markdown pages. If there are duplicate keys in them, the ones from the **main entry have the higher priority**. For example: |
| 13 | |
| 14 | ::: code-group |
| 15 | |
| 16 | ```md [./slides.md] |
| 17 | --- |
| 18 | src: ./cover.md |
| 19 | background: https://sli.dev/bar.png // [!code highlight] |
| 20 | class: text-center |
| 21 | --- |
| 22 | ``` |
| 23 | |
| 24 | ```md [./cover.md] |
| 25 | --- |
| 26 | layout: cover |
| 27 | background: https://sli.dev/foo.png // [!code highlight] |
| 28 | --- |
| 29 | |
| 30 | # Cover |
| 31 | |
| 32 | Cover Page |
| 33 | ``` |
| 34 | |
| 35 | ::: |
| 36 | |
| 37 | They will end up being equivalent to the following page: |
| 38 | |
| 39 | ```md |
| 40 | --- |
| 41 | layout: cover |
| 42 | background: https://sli.dev/bar.png // [!code highlight] |
| 43 | class: text-center |
| 44 | --- |
| 45 | |
| 46 | # Cover |
| 47 | |
| 48 | Cover Page |
| 49 | ``` |
| 50 | |
| 51 | ## Importing Multiple Slides |
| 52 | |
| 53 | When an external markdown file contains multiple slides, frontmatter next to `src` applies to **every imported slide**, not just the first one. This also applies when you [import specific slides](/features/importing-slides#importing-specific-slides). |
| 54 | |
| 55 | For example, the following sets `class: text-center` on every slide imported from `./chapter.md`: |
| 56 | |
| 57 | ```md [./slides.md] |
| 58 | --- |
| 59 | src: ./chapter.md |
| 60 | class: text-center |
| 61 | --- |
| 62 | ``` |
| 63 | |
| 64 | To configure only the first imported slide, put the frontmatter in the imported file itself. For example, put `clicks: 4` in `./chapter.md` so that only its first slide requires four clicks: |
| 65 | |
| 66 | ```md [./chapter.md] |
| 67 | --- |
| 68 | clicks: 4 |
| 69 | --- |
| 70 | |
| 71 | # Chapter Opening |
| 72 | |
| 73 | --- |
| 74 | |
| 75 | # Next Slide |
| 76 | ``` |
| 77 | |
| 78 | Putting `clicks: 4` next to `src` instead would override the click count of every imported slide, including slides that define their own `clicks` value. |
| 79 |