First, search the help docs and this forum. Maybe your question has been answered! The debugging steps can help, too. Still stuck? Delete this line and proceed.
What I’m trying to do
Can anyone help with this
I’m trying to have a Dataview table that shows a specific line of text containing “x”, in all pages. I usually tag lines with unique phrases and would like to show them in a table
Phrase examples : “WF//” “DQ//”
Line example: “DQ// This is line #today”
The table should include:
Page containing that line, the line of text containing “x”, tags of that line
Dataview currently only handles metadata, inline fields and/or list and tasks. Or put another way, it doesn’t actually read the file contents, and as such it can’t pull out those specific lines tagged with some “random” text like in your case.
However, your syntax could easily be transformed into something that Dataview is capable of reading and handling.
Using a task based approach
I’m not sure how many different phrases you use to distinguish your lines, so I’m going to preserve the phrases in the example below.
Here are two example tasks tagged similar to your example, and a query below (presumably in a different file) to list them again:
- [!] (phrase:: WD) This is a line #today
- [!] (phrase:: WF) Another lines with some other text #yesterday
## Queried result
WHERE status = "!"
Using Minimal theme, this display as:
I’ve got some custom CSS related to tags and fields, so your display may differ a little. But this display can also be customised in various ways, if one is so inclined.
One great advantage to doing it this way, is that you can now click on either of the lines, and it’ll link back to where you defined that “task”. The icon in front can be customised related to the character used in the task.
If you’re only doing a limited amount of phrases, you could potentially created a custom state for each of the phrases.
Similar query as a table
You could also do this query as a table query, and split out on the phrases, text and tags. This comes at the cost of loosing the link to the exact line of the task definition.
TABLE WITHOUT ID T.phrase as Phrase, text as Text, T.tags as Tags
FLATTEN file.tasks as T
regexreplace(T.text, "\(phrase::.*\) *", ""),
"#[^ ]+", "") as text
WHERE T.status = "!"
Which display as the following in my vault:
Using a list based approach
A similar markup can be used in only a list context, and the example would then look like:
- (phrase:: WD) This is a line #today
- (phrase:: WF) Another lines with some other text #yesterday
The query in this case would be similar to that of the table in previous section, but you would need to figure out a way to limit which list items to include or not. This could possible be done requiring the presence of the phrase field.
I’m not going to show these queries just now, but they’re indeed doable, although not entirely as clean as the task related queries.
Actually reading file contents
Unless your format has some external factors requiring it to be as you’ve examplified it, and you’re well versed in coding, I wouldn’t recommend this solution either. It can be done, but you’ll most likely end up with something being difficult to maintain and use.
In summary, I would strongly suggest using custom checklists (or decorated tasks) as suggested in the first section. I think they’ll provide you with the best option for easy markup, and easy retrieval in various context. See posts linked below for more information related to such decorated tasks.