MetaEdit plugin

Awesome! Glad to hear that.

Currently, no. I’ll add it to my backlog, though :slight_smile:

Thanks, @Christian. Is it possible for TFile to refer to the current file?

My hope is to use Templater to update the metadata I add to a file (both YAML and dataview). Here’s an example.

Pretend I have a file:

---
tags: people
alias: 
template: people
version: 2
---

# Metadata

Pronunciation:: 
Context:: [[Wyoming St]]

---

Then, pretend I update the template for these kinds of files to include a new field (e.g., Address::):

---
tags: people
alias: 
template: people
version: 2
---

# Metadata

Pronunciation:: 
Context:: 
Address::

---

I want a template that I can “expand” that will populate with the current file’s metadata already filled in. I am able to access the values for the YAML front matter using Templater. Mind you, I’m not a programmer, so I have no idea if there’s a better way to do this, but the following works for updating the YAML front matter:

---
<%* if ((tp.frontmatter.tags) == null) { _%>
tags: people
<%* } else if (tp.frontmatter.tags.contains("people")) { _%>
tags: <% tp.frontmatter.tags %>
<%* } else { _%>
tags: people, <% tp.frontmatter.tags %>
<%* } _%>

<%* if ((tp.frontmatter.alias) == null) { _%>
alias: 
<%* } else { _%>
alias: <% tp.frontmatter.alias %> 
<%* } _%>

template: people
version: 2
---

I’m hoping to use MetaEdit to update the dataview values. I think that a Templater Javascript Execution Command can handle the rest of the “expansion,” using the MetaEdit API. I’m thinking that I’ll essentially add one line per dataview value, like you do in the New Task template on your GitHub page.

<%*
const {getPropertyValue} = this.app.plugins.plugins["metaedit"].api;
tR = `
Address:: ${await getPropertyValue("Address", "TFile")}
`
 %>

I just don’t know how to make “TFile” or whatever I’m supposed to put between Address:: ${await getPropertyValue("Address", and )} refer to the current file.

Using Templater, there’s at least 2 ways to fill that parameter.
You could use tp.file.title(true), which gets the relative path to the file as a string.
The other solution would be to use app.workspace.getActiveFile(), which grabs the currently active file as a TFile.

3 Likes

Worked like a charm. Thanks, @Christian.

1 Like

Sorry for the very delayed reply, but could you provide some more detail on how you did this? I would love to replicate it for several things!

Specifically, the part I’m not understanding is how you embedded this in your monthly note - where did you save the code, etc.? :slight_smile:


Update: I figured it out! You need to wrap it in a dataviewjs code block:

```dataviewjs
--- code here ---
```
1 Like

How do I get the attribute called review to grow automatically every time I open a note?

1 Like

@Christian : In the features list is described the possibility to :

Edit last value in tags - works with Obsidian Tracker, too.

But it seems undocumented : could you please add more precisions ?

Thanks !

Most of my YAML meta are lists. How do I enter a new item as a list underneath the previous one. For instance:

Learned today:
- To use metaedit
- To use metaedit to create a list

Right now the way it is coming out is the following

Learned today: To use metaedit to create a list
- To use metaedit 

I’m sure there is a quick fix for this, but I couldn’t find anything.

Thanks!

This requires a listener to the “File opened” event. There might be a good implementation for a new MetaEdit feature that does this, but I’d have to think it through. For now, you could make a simple plugin for Obsidian that listens to that event and then calls the MetaEdit function if the attribute is present. :slight_smile:

Unfortunately, there’s not much in the way of quick fixes. Supporting proper YAML has been on my to-do list for the longest time, so it’s probably the very next thing I’ll do. Only arrays are supported at the moment (e.g., [1, 2, 3]).

1 Like

Tracker allows you to specify a value after the tag, i.e., #tag:value. So depending on which option is chosen, MetaEdit will either update the value, or the last part of the tag #here or #change/here, where here will be changed.

Hope this helps!

2 Likes

im not a developer, maybe i will try to learn how develop a plugin

thx for your reply, and plz consider to add this feature

1 Like

I’m trying to create a button that updates a specified metadata field (either YAML or dvfield) that is in the same file as the button. Very similar to the example documented on the plugin wiki - Complete Task in Dataview Table - just not in a dataview table. Seems it should be simple enough, however with my limited programming skills I cant’ work it out. Anyone know how to achieve this?

p.s. - thank you @Christian for making such amazing plugins - metaedit and quickadd have transformed how I use Obsidian.

1 Like

Hi, can you explain how you can delete property easily with the plugin ? I can’t seem to find a documentation for this.

Hey @Jeremy, glad to hear you like my plugins :slight_smile:

As for your question: I don’t have much experience with Buttons, but I tried my hand at making it work. From what I could tell, you’d want to either make it insert a Templater template into the file, where the template contains an API call to MetaEdit’s update.
You could also just make the button call a QuickAdd capture/macro, which could also call the update function.

When you open the MetaEdit menu, you’ll see on the right a :x:. Clicking that should allow you to delete the property.

1 Like

I asked because I thought there was an undocumented API function for deleting. Thank you again.

Ah, not currently. It’s planned, though. I am working on an update which would include it.

2 Likes

Thanks for getting back to me Christian. @imed actually helped me out by using the first method you suggested. For anyone that might be interested in the future here’s the template:

<%* 
const {update} = app.plugins.plugins["metaedit"].api 
const file = tp.file.find_tfile(tp.file.title) 
await update("<insert field>", "<insert value>", file) 
_%>
3 Likes

I’m currently trying to set up some habit tracking in obsidian. I want a button that will append a value to a list in the frontmatter. Any thoughts on this?