How can I create a new note inline with the note title formatted like so: [[T yyyy-mm-dd HH-MM]]

What I’m trying to do

Essentially I want to quickly create a link to an empy note that is a ticket. I want the note title to begin with ‘T’ space date as yyyy-mm-dd space time as HH-MM.

Things I have tried

Googling forums, youtube etc.

Essentially I suppose it breaks down into a couple of things.

  1. I want to create a new slash command.
  2. The slash command needs to insert the following “[[T yy-mm-dd HH-MM]]”

Any pointers on this would be great.

Thanks,

Tim.

I am not sure if I really understand what you are trying to do - if you want to create a new note with the title “T 2023-05-17 19:35”, just write this title down into double square brackets, and by clicking the link the note will be created.

If you are just looking for some automation (because you often need to create links like that, with the current date and time), I think that should be doable with either the Templater or the QuickAdd plugin.

1 Like

Thanks for your response.

Yes, I’m Looking to automate this process. I create about a dozen notes of this type a day. Each time I have to ‘craft’ the ticket title because the slash command does not work inside the note link ([[ ]]) and time is displayed with a colon separator, which isn’t compatible with note titles.

I have looked at Templater, but not quick add… I think Templater could do it, but I don’t know how to get Templater to give me inline link and creation of the note using a slash command.

Thanks again,

Tim.

Would this work?

  1. Template in Templater:
[[T <% tp.date.now("YYYY-MM-DD HH-mm") %>]]
  1. Or to place the tickets in a specified folder:
[[_tickets/T <% tp.date.now("YYYY-MM-DD HH-mm") %>]]
  1. Assign the template its own hotkey

EDIT:

You could use this to hide the folder path:

[[_tickets/T <% tp.date.now("YYYY-MM-DD HH-mm") %>|T <% tp.date.now("YYYY-MM-DD HH-mm") %>]]

Or someone else will know how to assign / move the tickets to a specific folder.

2 Likes

Excellent, this works like a charm. Hot Keys being the way to add inline commands. Thie ticket is an empty note (Which is expected). I guess I can populate that template further to create a Ticket Template with some standard text and front matter?

Thanks again all for this, it will save me much time and tedium!

Tim.

1 Like

Hi, Tim.

Yes. Templater has a setting for ‘Enable Folder Templates‘. With this, users can assign specific templates to specific folders.

So you can create one template to create the ticket file name (as above). You can then create a new template for tickets, adding whatever data you want each ticket to contain. When the file name is clicked and the file is created, Templater will create the file using the template assigned to the destination folder.

Someone else might well have better ideas for doing all of this, but the above works for me with keeping track of (and using different folder templates for) authors, books, plays, scripts, people, commissions, etc.

1 Like

Thanks to @anon63144152 for leading the way on how to use Templater in this request. You can however utilise more of Templater to also include text into your newly created note using something like the following template:

<%*
const ticketFolder = "_tickets/"
const newTicket = tp.date.now("[T ]YYYY-MM-DD HH-mm")

await tp.file.create_new(
  `---
tags: ticket
id: "${ newTicket }"
---

## Ticket: ${ newTicket }

Some other text
`, 
  ticketFolder + newTicket,
  false,
  app.vault.getAbstractFileByPath("") )

tR = `[[${ ticketFolder + newTicket }|${ newTicket }]]`
_%>

Assign a hotkey like shown before in this thread, and now when you trigger your hotkey you’ll now get a new note with content like:
image

Depending on the setting of false (or true) in one of the last lines, Templater will opt not to open a new window, or open a new window with the newly created note.

In the template I’ve also included how to include other variables using the `${ newTicket }` syntax, and since I added the app.vault.getAbstractFileByPath("/") to the latter part of the tp.file.create_new() I can also place any relative path in the file name parameter, and the new note will end up in that folder within your vault.

The last line includes the folder when creating the link, but if you’re fairly confident your file name is unique (which I would think it is), you could also use just: tR = `[[${ newTicket }]]`, and just get the [[T 2023-05-18 15-45]] variant.

Finally, this date format is not a complete ISO8601 format, meaning that if you later on decide you want to query how many ticket you got you would be able to use file.day to get the ticket date, but not the hour/minute. To accommodate this, you could potentially add some extra variables, and include those into the frontmatter of the new file. Just saying, but this might not be a requirement of yours.

2 Likes

Note that in the previous reply I specified the text directly to be used in the new file. If you setup a system like eightning suggests related to folder you might have an existing template to use for this purpose already, I’m in the following going to assume that’s named ticketTemplate(this can of course be whatever you want).

You would then need to modify the template to trigger by the hotkey to create tickets to look like:

<%*
const ticketFolder = "_tickets/"
const newTicket = tp.date.now("[T ]YYYY-MM-DD HH-mm")
const myTemplate = await tp.file.find_tfile("ticketTemplate")

await tp.file.create_new(
  myTemplate, 
  ticketFolder + newTicket,
  false,
  app.vault.getAbstractFileByPath("") )

tR = `[[${ ticketFolder + newTicket }|${ newTicket }]]`
_%>
2 Likes

To answer the original question, just so you know this avenue exists:

You can use the built-in Templates core plugin to make links in the format you want.

Write [[T {{date: yyyy-mm-dd HH-MM}}]] in a note in your templates folder, then use the “Insert Template” command to create the link (via command palette, ribbon button, hotkey if you set one, various other triggers you can setup with community plugins).

2 Likes

Or perhaps:

[[T {{date: YYYY-MM-DD HH-mm}}]]

Difference in the cases used for tokens:

https://momentjs.com/docs/#/displaying/format/

2 Likes

Thanks all for your help in extending the Ticket Template operation, I’ll definitely be incorporating a few of those, and doing a deep dive on Templater.

Also, yes eightening, I’ve been caught out with the case problem before!

Thanks again, you’re all awesome :sunglasses:

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.