Skip to content

Support for Templater Plugin #456

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Weiberle17 opened this issue Mar 2, 2024 · 5 comments
Open

Support for Templater Plugin #456

Weiberle17 opened this issue Mar 2, 2024 · 5 comments

Comments

@Weiberle17
Copy link

🚀 The feature, motivation and pitch

I would love to be able to use my Templater templates.
The basic template ist something like <% tp.date.now() %>.
I use it for daily notes to link between them. Which isn't possible with the default templates.
Right now I need to create the file in the Obsidian App bevor I can edit it within Neovim.

Alternatives

The custom commands are nice but I would have to setup two templates. One that runs whenever I open the file in the app and one for Neovim.

Additional context

https://github.com/SilentVoid13/Templater
This is the plugin.

@sotte
Copy link
Contributor

sotte commented Mar 4, 2024

You can define custom substitutions here: https://github.com/epwalsh/obsidian.nvim/blob/main/README.md?plain=1#L372

I have some that look like this:

      templates = {
        subdir = "templates",
        date_format = "%Y-%m-%d-%a",
        time_format = "%H:%M",
        substitutions = {
          yesterday = function()
            return os.date("%Y-%m-%d", os.time() - 24 * 60 * 60)
          end,
          yesterday_with_weekday = function()
            return os.date("%Y-%m-%d-%a", os.time() - 24 * 60 * 60)
          end,
          today_with_weekday = function()
    ...

But the syntax is different than the templater plugin.

@Weiberle17
Copy link
Author

Yes I know and I like the way this is implemented.
I would just really like to be able to have one template that works independent of the method in which I created the note. Sometimes I use Obsidian on my phone before I use it on the computer for example.
If this is out of scope I absolutely understand and you can close this issue. I just thought I'd ask for this feature.

@sotte
Copy link
Contributor

sotte commented Mar 5, 2024

I see.

One workaround could be to have two versions of the same template, one for obsidian.nvim and one for the templater plugin. This is, I admit, tedious.

If this is out of scope I absolutely understand and you can close this issue. I just thought I'd ask for this feature.

This is up to @epwalsh to decide.

@MovieMaker93
Copy link

I'd love this feature too. The templater plugin is way cooler than the default one

@jtprogru
Copy link

jtprogru commented Feb 8, 2025

I need this feature! I like Templater and NeoVim. In Templater I use custom scripts like this:

function custom_uuidv4() {
    return ([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g, c =>
        (c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16)
    );
}

module.exports = custom_uuidv4;

In all my templates created for Templater I use my custom function, i.e.:

---
id: <% tp.user.custom_uuidv4() %>
creation_date: <% tp.file.creation_date("YYYY-MM-DDTHH:mm:ss") %>
modification_date: <% tp.file.last_modified_date("YYYY-MM-DDTHH:mm:ss") %>
type: daily_note
tags:
- journal/daily
aliases:
---

In this example I call my custom func <% tp.user.custom_uuidv4() %>. @epwalsh we believe in you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants