# Obsidian API/Function to work with Frontmatter/File Content

**URL:** <https://forum.obsidian.md/t/obsidian-api-function-to-work-with-frontmatter-file-content/86079>\
**Category:** Devs: Plugins & API\
**Created:** [July 29, 2024, 3:21am UTC](https://forum.obsidian.md/t/obsidian-api-function-to-work-with-frontmatter-file-content/86079 "2024-07-29T03:21:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![theRandomizer](https://forum.obsidian.md/user_avatar/forum.obsidian.md/therandomizer/32/25011_2.png) [@theRandomizer](https://forum.obsidian.md/u/theRandomizer)\
**Post date:** [July 29, 2024, 3:21am UTC](https://forum.obsidian.md/t/obsidian-api-function-to-work-with-frontmatter-file-content/86079/1 "2024-07-29T03:21:09Z")

</div>

I am trying to modify the content stored in files based on the results of a Templater Script. I am able to modify the content of files using `app.vault.modify()` but this file also gets rid of the frontmatter. I want to modify the content of the file without touching the frontmatter.

The below API seems to be what I need but I do not know how to use it. The function does not seem to be accessible using the `app` object in the Obsidian Developer Tools.

> **[getFrontMatterInfo - Developer Documentation](https://docs.obsidian.md/Reference/TypeScript+API/getFrontMatterInfo)**
>
> getFrontMatterInfo getFrontMatterInfo() function Given the contents of a file, get information about the frontmatter of the file, including whether there is a frontmatter block, the offsets of where …

This command also seems to walk about this function but once again I am not able to use it from Developer tools.

> [@How to get current file content without YAML frontmatter?](https://forum.obsidian.md/t/how-to-get-current-file-content-without-yaml-frontmatter/26197/12):
>
> The proper way to handle this now is using getFrontmatterInfo ([obsidian-api/obsidian.d.ts at 8b2eda0f24285636c8aa116972643e5233a23dc1 · obsidianmd/obsidian-api · GitHub](https://github.com/obsidianmd/obsidian-api/blob/8b2eda0f24285636c8aa116972643e5233a23dc1/obsidian.d.ts#L1735)) let { contentStart } = getFrontMatterInfo(fileContents); // removing the frontmatter from a file let withoutFrontmatter = fileContents.slice(contentStart); // swapping the frontmatter let replacedFrontmatter = '---\nfoo: bar\n---\n' + fileContents.slice(contentStart); // prepending text to file without breaking frontmatter l…

How would I go about using this function/API?

---

<div class="post-metadata">

**Author:** ![drongo](https://forum.obsidian.md/letter_avatar_proxy/v4/letter/d/439d5e/32.png) [@drongo](https://forum.obsidian.md/u/drongo)\
**Post date:** [October 23, 2024, 3:21pm UTC](https://forum.obsidian.md/t/obsidian-api-function-to-work-with-frontmatter-file-content/86079/2 "2024-10-23T15:21:28Z")

</div>

```ts
import { getFrontMatterInfo } from 'obsidian'

```

---

<div class="post-metadata">

**Author:** ![ush](https://forum.obsidian.md/letter_avatar_proxy/v4/letter/u/8e7dd6/32.png) [@ush](https://forum.obsidian.md/u/ush)\
**Post date:** [October 24, 2024, 7:02am UTC](https://forum.obsidian.md/t/obsidian-api-function-to-work-with-frontmatter-file-content/86079/3 "2024-10-24T07:02:53Z")

</div>

> [@drongo](#):
>
> `import { getFrontMatterInfo } from 'obsidian'`

That import doesn’t work in templater scripts. In templater, you should be able to access the function by `tp.obsidian.getFrontMatterInfo`
