Works for me, thanks
Edit:
Ok, I’m slightly buffoonish. I was missing “text =”, e.g.,
if e.data.name:startsWith("Journal/Day/") then
return {
text = space.readPage("Library/Templates/Daily Note"),
perm = "rw"
}
So I’ve figured that out. Now I have to figure out why it is printing the raw contents of the template rather than evaluating it as a template. Back to work…
Edit 2:
I’m consistently, regardless of the method I use, able to get the raw contents of a template into the file I create, but, for example, the cursor location placeholder “|^|” will print in the resulting output. I’m not (so far) able to insert a template as a template.
The use case here is that I often will type extensive notes in a meeting, and I’ll want to reference that Jane Doe said something, so I will, in realtime, create the link to [[Person/Jane Doe]]
via a prompt (e.g., Alt-Shift-P for “person”). This doesn’t create the file, only the link to it. I’ll then go back and visit any people, organizations, or other meetings referenced in the notes and fill in any details on the respective pages. Previously I had a hook defined that would create a page from a template for, e.g., any visit to “Journal/Day/", "Meeting/”, etc., so that I could even manually visit a page and get the right template applied to the resulting page.
I fear I’m overthinking this and that there’s a simpler way to do what I’m trying to do.
Original Post:
This isn’t working for me right now. I currently have the following space-lua
in a configuration page (I’ve thrown this together quickly so it’s not perfect):
-- Create pages from template automatically based on path
event.listen {
name = "editor:pageCreating",
run = function(e)
-- Daily Note journal template
if e.data.name:startsWith("Journal/Day/") then
return {
space.readPage("Library/Templates/Daily Note"),
perm = "rw"
}
-- Weekly Note journal template
elseif e.data.name:startsWith("Journal/Week/") then
return {
--space.readPage("Library/Templates/Weekly Note"),
perm = "rw"
}
-- Meeting template
elseif e.data.name:startsWith("Meeting/") then
return {
--space.readPage("Library/Templates/Meeting"),
perm = "rw"
}
-- Person template
elseif e.data.name:startsWith("Person/") then
return {
--space.readPage("Library/Templates/Person"),
perm = "rw"
}
-- Organization template
elseif e.data.name:startsWith("Organization/") then
return {
--space.readPage("Library/Templates/Organization"),
perm = "rw"
}
else
return
end
end
}
The if
block is working properly based on testing each of the conditions. What isn’t working is pulling the template. Only the Daily Note template exists now, but I can create a new page from the template manually with no problem. With this function, I just get a blank page for the newly created page. Am I missing a space.newPageFromTemplate
function in the documentation?
(Note that I’ve tried this stripped down just to the daily journal and an else
, and it still fails, though, again, I’ve confirmed that the if
conditions are evaluating correctly.)
While this works, I’m not sure the behaviour is consistent. I will investigate and raise a GitHub issue