# Create tag from the metadata value in YAML

**URL:** <https://forum.obsidian.md/t/create-tag-from-the-metadata-value-in-yaml/52650>\
**Category:** Help\
**Created:** [January 19, 2023, 9:58am UTC](https://forum.obsidian.md/t/create-tag-from-the-metadata-value-in-yaml/52650 "2023-01-19T09:58:25Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![holroy](https://forum.obsidian.md/user_avatar/forum.obsidian.md/holroy/32/77699_2.png) [@holroy](https://forum.obsidian.md/u/holroy)\
**Post date:** [January 22, 2023, 9:12pm UTC](https://forum.obsidian.md/t/create-tag-from-the-metadata-value-in-yaml/52650/7 "2023-01-22T21:12:21Z")

</div>

There are three ways forward, as I see it (surely even more options exists, but these three are the ones I’m going to focus on): Leave the value within that inline field, use `api.FileManager.processFrontmatter()` to store it, or use the metaedit plugin to store it.

## Leave it as is

I’m not quite sure what you gain by moving it from `Status: ` into the tags, and maybe it’s not mine to question. And as I eluded to there might an issue related to changing the file from within itself, and when running a dataview query (or metaedit change), you’ve potentially got an issue with how to trigger, and when to trigger the update of the YAML.

I don’t see how to safely get a trigger to initiate either query just when its changes, and the alternative is that the queries trigger way to often, and change it when it’s not needing to change, and _you might_ end up in a race condition when editing the file between your manual edits, and the changes that either query would want to do.

Finally, for many searches and queries where you would want to use the values of #todo/Doing, you just as easily do as `Status = "Doing"` or `file.Status = Doing`, instead of doing something like `econtains(file.etags, "#todo/Doing")` or similar. So my point being is not that I don’t want to help you, but maybe question whether you really want/need to do this.

## Using the metaedit plugin

I’ve not used the metaedit plugin so far, but I see in the home page, [GitHub - chhoumann/MetaEdit: MetaEdit for Obsidian · GitHub](https://github.com/chhoumann/MetaEdit#kanban-helper-guide), there is a KanBan helper guide, and some examples on how to call the API to trigger changes using either _dataview_ or _Templater_.

So I can’t really give any examples on how to do it, but it should be doable.

## Using api.Filemanager.processFrontmatter

This is potentially your best bet to do changes to the frontmatter (another name for the YAML section), but it comes with its own caveats. Firstly, it’s a bit technical and requires some coding experience. Secondly, in the current (official) version of 1.1.9 there is an issue related to empty frontmatter sections (which shouldn’t pose a problem in your case, though).

> [@Issue using app.fileManager.processFrontMatter](https://forum.obsidian.md/t/issue-using-app-filemanager-processfrontmatter/51233):
>
> I’ve been trying to change the frontmatter from within a Templater template, and it mostly goes OK, with the exception on when the frontmatter is present, but empty like in the following file: --- --- Empty frontmatter In this particular case I can’t seem to insert a new value. Is this just me doing it the wrong way, or is this a bug/feature of either Obsidian and/or Templater? Could someone enlighten me, as to what to do with this, or how to insert a value into the empty frontmatter? play_button Files…

In the issue above, I present code to actually change the frontmatter using this method, where the focus is on the issue with the empty frontmatter section. Two notes to be made, though, the issue itself is resolved in one of the insider version (which I currently don’t have access to), so the next official version will have that fixed. The second note is that I’ve presented a workaround later on in the same thread.

So once you figure out a safe way to avoid the race condition issue, and potentially how to handle multiple values in `tags:` and you wanting to change only one of them, this is indeed a plausible way forward.

I don’t have the time for at least a few days, to try suggesting code to solve it, but if you’re a programmer maybe this is enough information to get you going?

I’ve been thinking that possible this could be a way to handle some of the issues:

- Add another field like `LastStatus` into the frontmatter
- Whenever `Status` and `LastStatus` are identical, bail out and don’t do anything, as the status haven’t changed. (The next points, is therefore only _when it has changed_)
- Prepare a object with the new value for `LastStatus`, and the new value of `todo/...`
- Send this object into a method called by `api.FileManager.processFrontmatter`, where you then:
  - Split the `tags` field, and remove the old `todo/...` field, and insert the new value of it, and join up the values again
  - Update the frontmatter with both values

This _should_ be safe, as `processFrontmatter` is supposed to be an atomic update of the frontmatter, but I’ve never tried to do it on the current file.

---

_[View the full topic](https://forum.obsidian.md/t/create-tag-from-the-metadata-value-in-yaml/52650)._
