# 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:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![avelskol](https://forum.obsidian.md/user_avatar/forum.obsidian.md/avelskol/32/41857_2.png) [@avelskol](https://forum.obsidian.md/u/avelskol)\
**Post date:** [January 19, 2023, 9:58am UTC](https://forum.obsidian.md/t/create-tag-from-the-metadata-value-in-yaml/52650/1 "2023-01-19T09:58:25Z")

</div>

### Things I have tried

### What I’m trying to do

I am new in Obsidian and YAML, but experienced in programming. I have not found a solution if it exist to my problem.

In the YAML block, I would like to use the value (“Doing”) of metadata (Status) to create the tag todo/Doing. In Unix shell, it would be something like that tags: todo/$Status.

My idea is to link the task management with the kanban and Checklist plugins.  
When I move a kanban card from the column e.g. “Doing” to “Done”, the Metaedit plugin allows to update the value of the metadata in the the associated note. I would like to use this metadata to update the tag todo/xxx , that is used by Checklist.

Thanks in advance.

---

<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 19, 2023, 10:03am UTC](https://forum.obsidian.md/t/create-tag-from-the-metadata-value-in-yaml/52650/2 "2023-01-19T10:03:03Z")

</div>

I think the tricky part is detecting when it changes, and then trigger the metaedit script. It seems kind of wasted to have a query going continuously to transfer the value from status to a tag…

Not sure on how to trigger it…

---

<div class="post-metadata">

**Author:** ![avelskol](https://forum.obsidian.md/user_avatar/forum.obsidian.md/avelskol/32/41857_2.png) [@avelskol](https://forum.obsidian.md/u/avelskol)\
**Post date:** [January 19, 2023, 2:17pm UTC](https://forum.obsidian.md/t/create-tag-from-the-metadata-value-in-yaml/52650/3 "2023-01-19T14:17:06Z")

</div>

Thanks.  
In fact the meta edit triggering is already set and operational, because it is the one used by the kanban plugin, when a card is moved from one column to another.

---

<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 19, 2023, 3:15pm UTC](https://forum.obsidian.md/t/create-tag-from-the-metadata-value-in-yaml/52650/4 "2023-01-19T15:15:03Z")

</div>

So what have you done/ accomplished so far? Do you have something which nearly works, or gives an error message?

---

<div class="post-metadata">

**Author:** ![avelskol](https://forum.obsidian.md/user_avatar/forum.obsidian.md/avelskol/32/41857_2.png) [@avelskol](https://forum.obsidian.md/u/avelskol)\
**Post date:** [January 19, 2023, 3:38pm UTC](https://forum.obsidian.md/t/create-tag-from-the-metadata-value-in-yaml/52650/5 "2023-01-19T15:38:15Z")

</div>

I have tested some stuff but my lack of knowledge makes me blind.

I have tried to do something in the YAML Block, but I do not know how to get the value of the key Status and how to “stick” it to the string “todo/” to create a new tag

* * *

## Status: Doing tags: todo/Status

This don’t work

I jave also to use the Dataview query language inline.

#todo/`= this.Status`

It seems to work when I visualise the markdown, but un fact it is only visualisation, the created tag is #todo/`= this.Status`…

After that, I spent a lot of time on internet to try to learn how it works and how I can get the value of a key in the YAML and how to do what I would do in unix Shell, like that

Status=“Doing”  
% echo $Status  
Doing  
% tag=“todo/”$Status  
% echo $tag  
todo/Doing

or like that in python:

> > > Status=“Doing”  
> > > tag=“todo/”+Status  
> > > print(tag)  
> > > todo/Doing

Thanks for your help ou to point me some ressources to learn.

---

<div class="post-metadata">

**Author:** ![avelskol](https://forum.obsidian.md/user_avatar/forum.obsidian.md/avelskol/32/41857_2.png) [@avelskol](https://forum.obsidian.md/u/avelskol)\
**Post date:** [January 22, 2023, 3:25pm UTC](https://forum.obsidian.md/t/create-tag-from-the-metadata-value-in-yaml/52650/6 "2023-01-22T15:25:49Z")

</div>

Is my question clear enough ?  
Is there anybody that could help me or provide me some references to understand how the variables work in the obsidian YAML, and to have some references on the syntax to use ?  
Thanks in advance

---

<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.

---

<div class="post-metadata">

**Author:** ![system](https://forum.obsidian.md/uploads/default/original/3X/b/e/bec35fbd23ab28909bb6bfe62cb32eb82dd34019.png) [@system](https://forum.obsidian.md/u/system)\
**Post date:** [April 22, 2023, 9:12pm UTC](https://forum.obsidian.md/t/create-tag-from-the-metadata-value-in-yaml/52650/8 "2023-04-22T21:12:40Z")

</div>

Closed on April 22, 2023, 9:12pm UTC

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
