Extend default template functionality

It would be very powerful to be able to automatically invoke templates when new pages are created. As it stands currently, it seems you can only do this for journal pages, although the syntax used to set default-templates in config.edn–

 {:journals "my_template_name.md"}

–seems to suggest an intention to eventually allow other sorts of default templates to be created.

I’ve seen a number of requests for this feature; here are a few:
Automatically evoke a template when a new page is created
Default Template for New Page
Can we create Default Template for New Pages - Not only for Journals?

Obsidian has a plugin that achieves a similar functionality. It allows different default templates to be set for pages created in different folders (if I remember correctly), with the innermost template used when a page is created inside multiple nested folders that contain default templates. I would think that a similar scheme using parent blocks’ attributes could work well for Logseq.

Would love to see some interest in this-- I think it would be a very powerful feature. Any idea if there are plans for this? Also, I’m no expert on the plugin API, but is it possible to implement this with a plugin?

I am pretty sure a plugin could implement this, but I don’t understand what you mean by this:

because a page doesn’t have a parent block…

For me it would be enough if in empty pages there were some buttons to invoke templates.

At the moment one can use Smart Blocks plugin to create a button that invoke a template and even a button that invoke a template containing other buttons. By taking advantage of this, if Logseq let you specify a template for all new pages, I would use it to show a series of buttons by Smart Blocks, so that I can choose the template every time I create a page with a click.

But I imagine you have another workflow in mind?

Thanks for the clarification request-- my original post was, in retrospect, unclear. The “similar scheme” I mentioned would only work for block templates, not page templates.

FWIW, I would love to be able to create default templates for both pages, and for blocks . Ideally, I’d like to be able to define a block template that is automatically invoked every single time a block is created. There are certain properties I would like all of my blocks to have, and invoking a template with the slash command or clicking a button every time I create a new block would becoming repetitive and cumbersome. A default template that applied to all blocks would solve this issue.

Same goes for pages. A default template that would automatically be invoked every time a page is created, whether it is by pressing the new page button, creating a [[wikilink]] to a new page, or any other method.

[From there, you could add functionality to create additional default templates to be more narrowly applied to blocks/pages in certain contexts (for example, only to blocks created under parent blocks with specific attributes). I am less certain about the best way to implement this, especially in the case of pages, which as you pointed out don’t have parent blocks. So for now, I want to focus on being able to create a default template for all blocks, and/or a default templates for all pages.]

Any pointers on how this might be implemented as a plugin? I don’t know that I have the knowledge/skills currently to implement it myself, but am curious to learn more and perhaps inspire others to give it a try.

check out the powertags plugin: GitHub - hkgnp/logseq-powertags-plugin: logseq-powertags-plugin

Thanks for the suggestion! I really appreciate it. Powertags seems like a great tool, props to the creator.

As far as I can tell, I wouldn’t be able to use it to create a default template that would automatically apply to all blocks. It does occur to me though, the Powertags plugin could have really powerful synergy with a functionality to create inherited properties-- similar to the attribute inheritance feature in the note taking app Trilium Notes. Overall I think Logseq is more powerful and user-friendly than Trilium but attribute inheritance is a great feature.

The properties (attributes) in logseq are already inherited. the default simple query only assumes inheritance of two or three levels (I can’t remember at all) but with advanced queries the inheritance can extend to the deepest children:

the following example is from logseq discord’s #queries channel:

If the parent block has property author and the child has property book —

{:query [:find (pull ?author-block [*])
         :in $ %
         (property ?author-block :author "Oscar Wilde")
         (property ?book-block :type "book")
         (parent ?author-block ?book-block)]
 :rules [[(parent ?p ?c) [?c :block/parent ?p]]
         [(parent ?p ?c) [?c :block/parent ?t] (parent ?p ?t)]]}