What is the best practise for inline string values in dataview

Things I have tried

  • Searched the forum
  • Read the dataview documentation on data types

What I’m trying to do

I’d like to set an field at the top of my file to be a string. I know that I could just type the text, but I’m wondering what the best practice is, especially considering my field might have punctuation in it.

Would it be better to surround the text in double quotes?

e.g. fullTitle:: "Harry Potter and the Philosopher's Stone"

I tried some variants for a text and a link with punctuation, which produces the following view with source mode to the left, and reading mode to the right:

The second alternative didn’t enjoy being too close to the definition, as it then failed to do the query on the immediate following line (which could be a bug, not sure on that one), but it does get the value of title2 correct.

Which is better? Hard to say, but I tend to use no quotes, as long as I can. The icky part comes when adding dates and duration and trying to define multiple values in the same line. I’ve not fiddled enough to say conclusively then that this or that is the better option.

Here is a similar case, showing some of the challenges with multiple values for durations and names:

If the duration is properly parsed, it’ll calculate the proper way to write it, so we see that dur3 is just texts (or strings), but multiple values. But how do you get multiple durations on one line? Not dur2, as that sums it up, so in my short test period, I had to do two definitions, as for dur4 to get two durations. Not sure if a better way exists.

And if you want multiple names to actually be a list, you have to use quotes to separate the values.

So what does this mean, is it better with quotes or not? What if we add some dates into the mix, as well. How do we preserve those, as single values or multiple values?

Here we see that we need to not use quotes to get it to actually be a date (which we can add durations like a day to). See how the quoted versions, just adds the text “1 days” to the text of “2023-01-21”.

So it’s a little finicky depending on your values, and what you want out of it. Sometimes you do need the quotes, and sometimes it’s better to not use the. Sorry for any confusion I’ve created for you!

Full markdown for these images
### Quotes
title1:: "Harry Potter! and the Philosopher's Stone [[Note 1]], 60 m"
Title1 is `$= dv.current().title1 `

### Square brackets
[title2:: Harry Potter! and the Philosopher's Stone [[Note 1]], 60 m ]  
Title2 is `$= dv.current().title2 `

Title2 is `$= dv.current().title2 `

### Nothing
title3:: Harry Potter! and the Philosopher's Stone [[Note 1]], 60 m
Title3 is `$= dv.current().title3 `

dur1:: 58 m 120s
dur2:: 58 m 120s, 59 m 60s
dur3:: "58m 120s", "59m 60s"
[dur4:: 58m 120s], [dur4:: 59m 60s]

```dataview
table without id dur1, dur2, dur3, dur4
WHERE file.name = this.file.name
```

multi1:: John Smith, Jane Doe
multi2:: "John Smith", "Jane Doe"

```dataview
table without id multi1, multi2
WHERE file.name = this.file.name
```

date1:: 2023-01-01
date2:: 2023-01-11, 2023-01-12
date3:: "2023-01-21", "2023-01-22"

```dataview
table without id date1, date2, date3
WHERE file.name = this.file.name
```

```dataview
table without id
  date1 + dur(1 day),
  date2[0] + dur(1 day),
  date3[0] + dur(1 day)
WHERE file.name = this.file.name
```
1 Like

Hey @holroy - thanks so much for the extremely a detailed reply. They certainly are finicky!

Up until now I’ve actually been very lucky with my metadata as it’s either a link people:: [[John Doe]] or a tag project-status:: #ps/curerent / type:: #source/book and with the above syntax creating lists hasn’t given me any trouble.

As for my string field, I’m considering going with double quotes as it seems the safest ans also future proofs me incase I need a 2nd value in the field. Also then all my string fields can and will look the same.

1 Like

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