Org-roam capture templates function to move to point in file

I am attempting to use the org-roam dailies capture templates to insert entries underneath a headline specified by the an org-roam-dailies-capture-templates key. I was hoping to get it to look something like this:

* 2022-09-25 Sunday
** logs
*** 20:00 Log Entry 01
This is a log entry

*** 23:00 Log Entry 02
This is also a log entry

** reflections
*** 22:00 Reflection Entry 01
This is a reflection entry

*** 23:30 Reflection Entry 02
This is also a reflection entry

So I tried to do this the way I would with org-capture-templates, by using a custom function with the :target property to move point to the respective headline and then insert my entry. However, it seems that org-roam-capture-templates and org-roam-dailies-capture-templates don’t accept the same arguments as regular org-capture-templates. In particular, custom functions to move the point within the file are not supported as far as I can tell.

A sample of the code that I hoped would achieve my purpose is

org-roam-dailies-capture-templates
("l" "log entry" entry
      "* %<%H:%M>\n%?"
      :target (file+function "%(expand-file-name "%<%Y-%m>.org" org-roam-dailies-directory"
                             (function organum-capture-journal-target-heading))
      :journal-type "logs")

and the untested function to move to the heading is

(defun organum-capture-journal-target-heading ()
  "Return a file target for a journal capture."
  (let ((date-heading (format-time-string "%Y-%m-%d %A"))
        (journal-heading (org-capture-get :journal-type)))
    (goto-char (point-min))
    (if (re-search-forward
         (format org-complex-heading-regexp-format
                 (regexp-quote date-heading))
         nil t)
        (beginning-of-line)
      (goto-char (point-max))
      (unless (bolp) (insert "\n"))
      (insert "* " date-heading "\n")
      (beginning-of-line 0))
    (if (re-search-forward
         (format org-complex-heading-regexp-format
                 (regexp-quote journal-heading))
         nil t)
        (beginning-of-line)
      (goto-char (point-max))
      (unless (bolp) (insert "\n"))
      (insert "* " journal-heading "\n")
      (beginning-of-line 0))))

i am not sure the above function works, but it hopefully captures the idea of what I am attempting to do. Is there any way for me to achieve this with org-roam’s capture templating system?

How about something simpler?

  (setq org-roam-dailies-capture-templates
        '(("l" "Logs" plain ""
           :target
           (file+head+olp "%<%Y-%m>.org" ""
                          ("%<%Y-%m-%d %A>" "logs" "%<%H:%M> log entry"))
           :empty-lines-after 2)
          ("r" "Reflections" plain ""
           :target
           (file+head+olp "%<%Y-%m>.org" ""
                          ("%<%Y-%m-%d %A>" "reflections" "%<%H:%M> reflection entry"))
           :empty-lines-after 2)))

The result is something like this image below. I believe it covers most of your requirements.

I didn’t understand exactly what you wish to do in some details from the code. Here are some main assumptions I made and consequences of the approach. I trust that you can adjust the code above to your exact requirements. I don’t use Org-roam-dailies so I’m sure I have missed some important aspects for you.

  • I take it that you would like “monthlies”
    This means one file per month and you want just one node (Org-ID per file). No headline nodes. I chose the plain option instead of entry. I believe that entry would result in creating a node for the headline of each day.

  • You would need to manually control the sequence of logs and reflections
    There are two keys for selections l for Logs and r for Reflections. You can use r before l. If the sequence is very important for you, you would need to ensure to create logs first, or manually exchange the sequence (easy to do with Org)

  • You may need to experiment with the :empty-lines-after property to get the spaces right for you
    I was not sure how important it is for you to get the blank spaces after each entry. You might need to get used to how the property works – I don’t fully understand it

  • You have number sequence like “Log Entry 01, Log Entry 02, etc.”
    I disregarded it – I don’t know how to achieve this with the template. If it is important, I guess you could use some function with %(sexp) – as documented in org-roam-capture-templates.

Sorry for the delay in responding, this achieves what I was looking for very well! The olp section of the target field was the key here. Thank you!!

Thank you for coming back and confirming