# How to separate page content from it's frontmatter?

**URL:** https://community.silverbullet.md/t/how-to-separate-page-content-from-its-frontmatter/1315
**Category:** Tricks & Techniques
**Created:** [November 29, 2024, 12:36pm UTC](https://community.silverbullet.md/t/how-to-separate-page-content-from-its-frontmatter/1315 "2024-11-29T12:36:21Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![mjf](https://community.silverbullet.md/user_avatar/community.silverbullet.md/mjf/32/654_2.png) [@mjf](https://community.silverbullet.md/u/mjf)
#### Post date: [November 29, 2024, 12:36pm UTC](https://community.silverbullet.md/t/how-to-separate-page-content-from-its-frontmatter/1315/1 "2024-11-29T12:36:21Z")

</div>

I use the following template:

````json
```template
{{#each {
page
    where
        name =~ /^Fleeting Notes\//
    order by
        date desc
    }
}}
#{{
    replace(name, /^Fleeting Notes.+/, "")
}} [[{{name}}]]
{{readPage(name)}}
{{/each}}
```

````

Is there a way to get only the page content (without the YAML frontmatter)  
and only the page frontmatter from the result of the `readPage()` function? I guess it’s doable with registering new custom functions somehow? Would somebody know how to achieve it? Thank you.

---

<div class="post-metadata">

### Author: ![Maarrk](https://community.silverbullet.md/user_avatar/community.silverbullet.md/maarrk/32/56_2.png) [@Maarrk](https://community.silverbullet.md/u/Maarrk)
#### Post date: [November 29, 2024, 2:10pm UTC](https://community.silverbullet.md/t/how-to-separate-page-content-from-its-frontmatter/1315/2 "2024-11-29T14:10:46Z")

</div>

Since the frontmatter is delimited with `---` we can use a regular expression to find where it is in text, and then replace this part of text with something else.

Luckily we don’t even have to figure out this expression ourselves, because finding the frontmatter is something that also the main silverbullet code needs to do (cf. [`lib/cheap_yaml.ts`](https://github.com/silverbulletmd/silverbullet/blob/cfbe8959d09b12accaccb678b8c861051d95e7e5/lib/cheap_yaml.ts#L3))

```auto
{{replace(readPage(name), /^---\n(([^\n]|\n)*?)---\n/, "")}}

```

---

<div class="post-metadata">

### Author: ![mjf](https://community.silverbullet.md/user_avatar/community.silverbullet.md/mjf/32/654_2.png) [@mjf](https://community.silverbullet.md/u/mjf)
#### Post date: [November 29, 2024, 2:31pm UTC](https://community.silverbullet.md/t/how-to-separate-page-content-from-its-frontmatter/1315/3 "2024-11-29T14:31:50Z")

</div>

@Maarrk Thanks. I haven’t known that I can work on the entire content like that (I’m probably too used to the line oriented unix approach that I was thinking of how to split it to lines and iterate over them etc.) 😄

---

<div class="post-metadata">

### Author: ![markalex](https://community.silverbullet.md/user_avatar/community.silverbullet.md/markalex/32/1861_2.png) [@markalex](https://community.silverbullet.md/u/markalex)
#### Post date: [October 16, 2025, 3:07pm UTC](https://community.silverbullet.md/t/how-to-separate-page-content-from-its-frontmatter/1315/4 "2025-10-16T15:07:26Z")

</div>

In v2 extraction of pages’ content can be done using existing functions:

```auto
index.extractFrontmatter(space.readPage(name), {
    removeFrontMatterSection = true,
    removeTags = true
  }).text

```
