obsidian-dataview
obsidian-dataview copied to clipboard
Add option to evaluate dataview codeblocks
Is your feature request related to a problem? Please describe. I use dataviews a lot in my daily entry template for tasks such as listing files I created/modified that day, what tasks I completed or should work on that day, and add #tags based on some conditional logic.
However Obsidian doesn't see the generated markdown created by the dataview code blocks, it just sees the code, so I can't actually search for any text or tags generated by dataview or see back-links to this entry from the files which are listed / linked.
Describe the solution you'd like I would like a way for a user to optionally have their dataview code blocks evaluated, i.e. evaluate the markdown that the dataview code block generates on the fly and write it to the actual file.
For instance, the content created by some dataviews may change throughout the day, but then it will be static forever after so it would be nice to have an easy way to save this generated output to the actual markdown file to take advantage of all the Obsidian linking-searching stuff.
- The user writes adds dataview code to their markdown file... # Example ```dataview list where file.ctime = date(today) ```
- They can see the on-the-fly evaluated output in read mode (just like dataview works currently):
# Example
- [[File 1]]
- [[File 2]]
- They hover over the dataview output, next to the
</> Edit this Block
icon, thereis a ▶️ icon to evaluate the expression and write it to the file.
They click it. And the file contents changes to:
# Example
- [[File 1]]
- [[File 2]]
Describe alternatives you've considered Another idea I had for evaluating the dataview codeblock non-destructively would be to not delete the dataview code, but just comment it out with %:
# Example
% \`\`\`dataview
% list where file.ctime = date(today)
% \`\`\`
- [[File 1]]
- [[File 2]]
Additional context
Haha this is a common ask. I can propose two approaches, one is to use a templater script to write to the file and use DV's API to generate what you need. However, if you're looking to only generate the link structure and the text itself isn't that important to you, wrap DV in an admonition. This is a plugin by javalent.
See #42 for the bigger discussion on freezing views.
Haha this is a common ask. I can propose two approaches, one is to use a templater script to write to the file and use DV's API to generate what you need. However, if you're looking to only generate the link structure and the text itself isn't that important to you, wrap DV in an admonition. This is a plugin by javalent.
I've been reading up on view freezing (#42). I understand why writing to file with templater works, but what would wrapping a DV query in admonition do? Also: dynamic templater commands run on file open, so the way to freeze queries -- such as for a daily log of modified files -- would be to just insert it once, right?
For templater, only insertion would work, dynamic commands do not since they do not create content, similar to dataview. I believe the admonition idea no longer works. I never tested it myself and merely saw on Discord that it worked.
My mistake on the templater - I confused dynamic and execution commands.
I'm closing this in favor of #42 since there are many variations on the idea. If there's something I overlooked, let me know and we can split that into a separate issue.