# Fold/toggle header

**URL:** <https://community.silverbullet.md/t/fold-toggle-header/954>\
**Category:** General\
**Created:** [September 6, 2024, 3:34am UTC](https://community.silverbullet.md/t/fold-toggle-header/954 "2024-09-06T03:34:55Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![zef](https://community.silverbullet.md/user_avatar/community.silverbullet.md/zef/32/7_2.png) [@zef](https://community.silverbullet.md/u/zef)\
**Post date:** [October 22, 2024, 5:48pm UTC](https://community.silverbullet.md/t/fold-toggle-header/954/7 "2024-10-22T17:48:36Z")

</div>

````auto
```space-script
silverbullet.registerEventListener({name: "editor:pageLoaded"}, async () => {
  const text = await editor.getText();
  if(!text.startsWith("---")) {
    console.log("No frontmatter, skipping folding");
    return;
  }
  const pos = await editor.getCursor();
  await editor.moveCursor(0);
  await editor.fold();
  await editor.moveCursor(pos);
  console.log("Folded frontmatter.")
});
```

````

Seems to do it. It may have a side effect of always scrolling the page a bit, depending on the cursor position, but perhaps that’s acceptable.

---

_[View the full topic](https://community.silverbullet.md/t/fold-toggle-header/954)._
