Where to put tags in Dataview? YAML or BODY?

Tags in yaml frontmatter don’t use “#”.

---
tag: tag1, tag2
---

or

---
tags:
  - tag1
  - tag2
---

thanks!! let me see if the below response works and if not, I’ll post an example.

question on this. i was using the page format so it’s clickable in my list, but when I try to create a table based on WHERE Author="[[Doe, John]]" it doesn’t work. Is it not possible to query on the author if it’s a page?

if they dont use the “#” sign, then is the downside of using it in YAML that I dont have the automatic dropdown of tag options? if so, then I guess putting it in the body would be better, as I have trouble remembering the tags w/o a prompt. esp. w/ nested tags.

if the only one value in Author field, use WHERE Author = [[Doe, John]] without quotation marks (quotation marks, in queries, are for strings)

yes, you don’t have the dropdown menu… but you can use “#”, found the tag in the menu and after remove the “#”.
yaml or body is your option…

1 Like

genius!

just to clarify, this one will take me some more learning, but a quick question.
speaking of metadata, can dataview display the date a note was created w/o me putting a field with that information? I’m trying to reduce friction and if the date is saved somehow with the page and I can retrieve it later, I dont need to add that manually in YAML or page body.

You can use file.cday- see: Data Annotation - Dataview

2 Likes

this is great. I just added it to the end of my sting of column names, but it’s displaying the column as “file.cday” — how do you show is AS let’s say “date created”?

file.cday AS "date created"

3 Likes

Is there a way to have an inline query that counts the inlinks with a certain tag? I keep running into problems addressing null.

This is what I have so far.
read:: =length(this.file.inlinks).file.tags.includes("#✅read")

In dql there’s no function called includes (that is a JS thing).

First step: filter the inlinks with the wanted tag:

`=filter(this.file.inlinks, (i) => contains(i.file.tags, "#✅read"))`

Second step: count the filtered inlinks

`=length(filter(this.file.inlinks, (i) => contains(i.file.tags, "#✅read")))`
3 Likes

Awesome! Thank you, again!

One more question. Is it then possible to use that number in a dataview table query. It doesn’t seem to recognize the answer as a number.

Your information are incomplete…
I can guess what’s in stake (a table query in another file that want to see the value in read:: field… the value obtained by the inline query…) but you need to explain it!

You are correct about what I am trying to do. I want the number to show up in another table. My query is in the body of the body of the file. Here is the table I am using. It worked when I manually put the number in it.

const {
    update
} = this.app.plugins.plugins["metaedit"].api
const buttonMaker = (pn, pv, fpath, text) => {
    const btn = this.container.createEl('button', {
        "text": text,
        "class": "button-55"
    });
    const file = this.app.vault.getAbstractFileByPath(fpath)
    btn.addEventListener('click', async (evt) => {
        evt.preventDefault();
        await update(pn, pv, file);
    });
    return btn;
}
const {
    createButton
} = app.plugins.plugins["buttons"]


for (let group of dv.pages("#🔰/🟢underway").where(p => p["seriesdateRead"] == null).groupBy(p => "🔰Current Contemporary Series")) {
    dv.header(4, group.key + ": " + group.rows.length);
    dv.table(["Cover", "Title", "Books Read", "X", "Progress"],
        group.rows.sort(k => k.file.link, 'asc').map(k => ["![Cover|90](" + k.cover + ")", k.file.link, k.read + " of " + k.total + " read", k["extra"], k["seriesdateStarted"] && k["read"] / k["total"] < 1 ? "<progress value=" + k["read"] / k["total"] + " max=1></progress>" :      
             createButton({
                 app,
                 el: this.container,
                 args: {
                     name: k["seriesdateStarted"] ? "Completed" : "Begin"
                 },
                 clickOverride: {
                     click: update,
                     params: [k["seriesdateStarted"] ? "seriesdateRead" : "seriesdateStarted", luxon.DateTime.now().toISODate(), k.file.link]
                 }
              })
           ])) 
}

This is my result.

I want the column called books read to show the numbers.

This is what I have in each series page.

Priority:: #series/:beginner:/:red_square:1st
Total:: =length(this.file.inlinks)
Read:: =length(filter(this.file.inlinks, (i) => contains(i.file.tags, "#🔰/✅read")))

I claimed about informations, not ALL information. :slight_smile:

The first part I guess it is any js to create a table with a button… but I’m limited in js and I never tried Metaedit.

But going directly to your point… Tacking this simple example:

Total:: `=length(this.file.inlinks)`

What’s the value in the field Total::? What’s the value in the field Total::? When dataview parse this field it reads =length(this.file.inlinks), not the result of the inline query, i.e., it reads the inline query expression, not the rendered output of that query.

If you run a table query in a series page targeting the field Total, by “magic” dataview can run in first place the inline query in Total:: before run the table query that target that inline query (if you add more sub-levels it doesn’t work).
But this method have a problem: because the two queries run in the same page (don’t forget, the value in “Total” is the inline query, not the inline query result) “this” points to the current file, not each file where you have the inline query! I.e., in your table above length(this.file.inlinks) gives you the number of inlinks to the file “series.current”, not to each book file.

This is the problem related with the use of this (or dv.current()) in inline queries to work as field values.

How to avoid this? You need to be specific in the inline query, i.e., you need to replace “this” by the file.link. For example: instead of

Total:: `=length(this.file.inlinks)`

you need to place something like

Total:: `=length([[File Name]].file.inlinks)`

(to a more automatic process, maybe defining a Templater with the right expression to add the part to the query).

Another way… you don’t need to target Total:: or Read:: fields, you can construct them in the table query. I don’t know how to do it in JS, but taking this DQL as an example:

TABLE WITHOUT ID
     "![Cover|90](" + k.cover + ")" AS "Cover,
     file.link AS "Book", 
     length(filter(file.inlinks, (i) => contains(i.file.tags, "#🔰/✅read"))) + " of " + length(file.inlinks) AS "Books Read"
...

Thank you! Just adding the file name fixed it.

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