I want to convert a dataview query in my daily notes to an embedded base to display certain properties from the past week’s daily notes as a sort of habit tracker - not the “current past week”, but the past week counted from the daily note it’s embedded into.
The relevant part of my Dataview query is:
FROM "journals"
WHERE date(file.day) <= date(this.file.day) AND date(file.day) >= date(this.file.day) - dur(7d)
Bases doesn’t seem to render HTML (I like to use <span class="blabla"></span> that I can then format via CSS) - but I can sorta circumvent this with emojis.
The if(habit_boolean.contains(true), "yes", if(date(file.name.slice(0, 10)) >= now(), "unknown", "no")) formula always results in “no”. Even for today’s date or true values.
Edit: I just realised that the way to render HTML in Bases with html() is coming to Obsidian in v1.10.0, only in Catalyst version for now.
now() is a datetime. Since you sliced the file name to ten characters, the function you’re after is likely today().
And if habit_boolean lives up to its name by being a checkbox property, then you’ll need to do habit_boolean == true because .contains() doesn’t work on boolean type. But if habit_boolean a list of booleans, then carry on.
Thanks, yes, the habit_boolean is a checkbox. I’ve tried this just now, but it still only giving “no” results even when the “habit boolean” property is checked:
There’s no such thing in HTML as all of those other functions you put inside of the html() function. Use html() on only the actual HTML.
Also, you’re creating a span that has a class but no content, so the result will show nothing when the file name’s date is today or later. If you meant to show something, then put your something into the formula where I wrote PUT SOMETHING HERE. But if you did mean for it to show nothing, then just delete that rudely shouting placeholder.
There’s no such thing in HTML as all of those other functions you put inside of the html() function. Use html() on only the actual HTML.
I followed an example I’ve seen on Discord, where they wrapped the entire formula in html(), and it seems to work all right for them. It also renders the HTML correctly for me, it just trips up on the if statement.
Also, you’re creating a span that has a class but no content, so the result will show nothing when the file name’s date is today or later. If you meant to show something, then put your something into the formula where I wrote PUT SOMETHING HERE. But if you did mean for it to show nothing, then just delete that rudely shouting placeholder.
Yes, I format the empty span via CSS, and include whatever content I want with ::before. (I picked up this habit with Dataview so that I wouldn’t need to modify many notes to change the looks, though it might be of reduced utility now that I can embed Bases.)
The formatted empty span works for the unknown status in the Bases code above, so that’s not the issue. It has to be something with the if(habit_boolean == true, "yes", part, but I can’t figure out what. That property is just a standard true/false checkbox, and using underscore in the property name instead of space is what that Dataview to Bases converter gave, so I assume it’s correct.
If that test doesn’t return the results you expect, my first two thoughts are:
Check your YAML in Source mode (not Live Preview nor Reading) to be sure they’re formatted as:
---
habit_boolean: false
---
… without any extras such as quotation marks.
Check that the file names are properly formatted thus passing or failing the if statement the way you expect.
If you can’t find what’s amiss, feel free to share examples of your YAML where it’s not working as you expect. Syntax there might or might not be the issue, but people could help you look for it.
After some testing, I figured out that the cause was that, unlike in Dataview, replacing spaces with underscores in property names doesn’t work in Bases.
I couldn’t find anything about this in the documentation or forums, but digging around in Discord revealed that the correct way to refer to property names with spaces in Bases is note["property name"]. And finally the formula works