0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【Obsidian初心者】tp.frontmatterがundefinedになるときの対処方法

Last updated at Posted at 2025-02-23

【Obsidian初心者】tp.frontmatterがundefinedになるときの対処方法

概要

  • 筆者はObsidian初心者です。
  • テンプレートからの新規作成時に、tp.frontmatterがundefinedになることでつまずきました。
  • 理由と対処法が示されたGitHubのDiscussionがあったため、備忘録として引用しながらまとめていきます。

実行環境

  • Obsidian1(Version 1.8.7)
  • Mac OS
  • 使用プラグイン:
    • Templater2(Version 2.9.3)

つまずいたこと

  • テンプレートからの新規作成時に、frontmatter(プロパティ)の内容を参照するためtp.frontmatter.titleを使用したが、undefinedになってしまう

  • 使用したテンプレート:

template.md
---
title: "<% tp.system.prompt("タイトルを入力")%>"
---

# <% tp.frontmatter.title %>
  • 作成されたノート(プロンプトには「テスト」を入力):
---
title: テスト
---

# undefined

tp.frontmatterがundefinedになるのを回避する方法

revised_template.md
---
<% const title = await tp.system.prompt("タイトルを入力") %>
title: <% title %>
---

# <% title %>

参考記事の解説

The documentation starts with a file that already has frontmatter.
Then, the tp.frontmatter is applied.
In other words, tp.frontmatter only works if the document already has pre-existing frontmatter to work with.
If you are using this template on a new file, there is no frontmatter to parse because there is no frontmatter yet.

  • 雑日本語訳:
    • ドキュメント3は、既にfrontmatterがあるファイルであることを前提にしており、そのときはtp.frontmatterを適用することができます。
    • すなわち、tp.frontmatterは、既にfrontmatterがあるファイルでのみ動作します。
    • もし、新規ファイルの作成にtp.frontmatterを含むテンプレートを使用した場合は、そのファイルにはまだfrontmatterがないので、tp.frontmatterでパージングできるfrontmatterがないと言えます。
  1. Obsidian公式ページ

  2. TemplaterのGitHubリポジトリ

  3. Templaterのfrontmatterに関するドキュメント

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?