Daily habit generate checkbox based on habit notes

What I’m trying to do

i have folder of habits. each habit in a note with description about it.
i want generate daily note with template where one section is habits. read all habit notes and generate an checkbox about each one in daily note.
that means one we have 3 habit note then we must have 3 checkbox in each daily note.
its dynamic that means if new habit note created then new daily notes must automatically add them too.(only new generated daily notes)
later in a review note i want to check these daily ckeckboxes for habit tracking.

Things I have tried

i tried on dataview but seems it is for gathering information only.
i tried templater but cant access other notes fields.

Thanks for help

You do need to combine the two. Use dataview within a template to gather which habits you want to have checkboxes, and then continue to output the tasks in the same template.

When using dataview in this context, remember to use the markdownTaskList() & co, to better facilitate the insertion into your new note. Do also remember to make it easy for your self to query task afterwards by leaving some tags or similar to differentiate the tasks.

Examples on this dataview and templater combo can be in this forum, and it’s hard to provide any example query since we don’t really know enough of your setup. But you should have something to start with using this post.

Thanks. but has problem. i used this:

let pages = dv.pages().where(p=>p.file.path.includes("Habits/Notes"))

		 .map(p => ['[ ] '+p.file.link

i want single dash but get double dash:

- - [ ] [[Projects/Habits/Notes/habit0.md|Habit0]]

while must be:

- [ ] [[Projects/Habits/Notes/habit0.md|Habit0]]

I would rather use dv.markdownTaskList, which produces the task lists, and not a list which you convert to a task. Or possibly I would even build the entire text manually to have better control over it.

My take on this would be to have a template (block) like the following in my daily note template:

<%* console.log("\nNew run")
const dv = app.plugins.plugins.dataview.api

const result = await dv.query(`
  TABLE WITHOUT ID habitKey, habitText
  FROM "ForumStuff/f70/f70542/Habits"
  WHERE type = "habit"

if ( result.successful ) {
  const values = result.value.values
  let dailyHabitTasks = `\n## Daily habits\n\n`

  values.forEach(([key, text]) => {
    dailyHabitTasks += (`- [ ] (habitKey:: ${ key }) : ${ text } \n`)
  tR += dailyHabitTasks
} else
  dv.paragraph("~~~~\n" + result.error + "\n~~~~")


In my simple test setup where I had habits containing text similar to:

type: habit
habitKey: walk
habitText: Go for a daily walk

When inserting the template I would get output like:

## Daily habits

- [ ] (habitKey:: early) : Stood up early today 
- [ ] (habitKey:: walk) : Go for a daily walk 
- [ ] (habitKey:: reset) : Reset house to clean 

This does in this form not containing a link back to the habit file, but it does have a simple key to use for later tracking and queries, and so on. Adding the file link should be rather easy changing the query, and the task line generation.

very thanks. but why like this image going to next line?

How does your dailyHabitTasks += line look like? You’re most likely inserting an extra lineshift somehow in that line.

this is:

HeHe… The console.log() could be removed. They’re there for debug purposes, and I forgot to remove them.

So it seems like your key value contains something causing it to create that new line, but I don’t get that newline. So not sure why that’s the case.

I would strongly consider having the extra key property in your habit notes, as that would make it easier to rename/change habits later on.

very thanks for your help. i changed to this and worked.

dailyHabitTasks += (`- [ ] ${ key }`)

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