event.listen {
name = "editor:pageCreating",
run = function(e)
if not e.data.name:startsWith("Permanents/") then
return
end
return {
text = "Template text here",
perm = "rw"
}
end
}
But how to cramp that frontmatter and it’s body in text?
I use hooks.newPage extensively. In v1, this was trivial, so losing it without a clear v2 example makes migration a bit rough.
The Library/Std/Page Templates implementation is already pretty similar. If you look at that and you have some experience with space lua, you should be able to make a drop in replacement for the hook.
But as far as your question goes … you just put it in there … that’s all. The text property is going to be the content of the page 1:1.
event.listen {
name = "editor:pageCreating",
run = function(e)
if not e.data.name:startsWith("Permanents/") then
return
end
local today = os.date("%Y-%m-%d")
local fullPath = editor.getCurrentPage()
local title
for part in fullPath:gmatch("[^/]+") do
title = part -- will end up with the last one
end
local text = table.concat({
"---",
"created: \"" .. today .. "\"",
"---",
"",
"# " .. title
}, "\n")
return {
text = text,
perm = "rw"
}
end
}