Template Tag issues (templates not filled every time)

Tried searching for a solution to my issue, but didn’t manage to find one. The closest question was this one I guess, but it got 0 answers :frowning: .

So, here’s my issue :

In my action, I have a “Define Template Tag” step where I’m defining a template :

image

Content :

# [[dateToday]]
→ 🗓 [[dateTodayName]]
→ Weekly Note : [[S[[dateWeekNumber]]]]
→ Future Log : [[FutureLog]]
⬅️ [[[[dateYesterday]]]] | [[[[dateTomorrow]]]] ➡️

Then, in a second step, I have a script where I’m doing some treatments and at the end I’m defining the tags used in the step 1. Here’s how I’m doing it :

if (dateToday !== "") draft.setTemplateTag('dateToday', dateToday);
if (dateTodayName !== "") draft.setTemplateTag('dateTodayName', dateTodayName);
if (dateWeekNumber !== "") draft.setTemplateTag('dateWeekNumber', dateWeekNumber);
if (dateYesterday !== "") draft.setTemplateTag('dateYesterday', dateYesterday);
if (dateTomorrow !== "") draft.setTemplateTag('dateTomorrow', dateTomorrow);

The problem is that, when I’m running the action, the values are replaced randomly.

Here are some examples of some outputs of the method draft.processTemplate("templateDaily") :


. . .

. . .


Does anyone have an idea why this is happening ?

I’m new to this, so please tell me if I’m doing something wrong :slight_smile:

Thank you :see_no_evil:

A number of things going on here…

  • The define template tag is designed to create a value placeholder that can be used later in a template (see docs. You seem to be trying to use to create a template, not a value.
  • The “tag” value should be only the tag name, not include the delimiters ([[ ]]). The delimiters are only used later in a template when you want to recall that value.
  • You can not define tags after they are used. Your script step after the other is out of order.

I’m missing pieces of this action to be able to explain further…perhaps take a step back and explain what you are trying to produce, and we can tell you how to do it.

1 Like

Thanks for your answer :slight_smile:

  • The define template tag is designed to create a value placeholder that can be used later in a template (see docs. You seem to be trying to use to create a template, not a value.

That’s exactly what I thought I’ll be doing. I need to deep digger in the docs to find how can I create a template. My idea was to create a template that other users could change based on their needs and by using specific tags that I’ve created in the script :dotted_line_face:

  • You can not define tags after they are used. Your script step after the other is out of order.

I know it is not logic this way, but when I added them in the correct order, nothing worked. So I tried reversing the order and weirdly enough, it worked :smiley:

  • The “tag” value should be only the tag name, not include the delimiters ([[ ]]). The delimiters are only used later in a template when you want to recall that value.

:man_facepalming: I have no idea why I was doing this… Thanks :slight_smile:

So, in other words, I’ll have to RTFM a little bit more :see_no_evil:
Thanks once again.
I’ll came back here if I do not find the necessary informations in the doc.

Again, if you tell us what you are going for as an end result, happy to point you in the right direction, and it might save some frustration.

Do you want to put this output into the current draft? If so, the “Insert Text” step is probably what you are looking for.

If you are already scripting, it may be best just to do it all in the script.

Ultimately, however, if you are generating custom template tag values, you want to generate them all, and have them all set before you process any template that is expecting to use those values.

It seems like you are trying to do dates and date math and may not need scripting at all, either. Take a look at the article on using templates for details on working with and adjusting dates in template tags. For example you can just do [[date|+1 day|%Y-%m-%d]] for tomorrow’s date.

I managed to do what I wanted, by having 2 scripts :

  • 1st : declaring the templates
  • 2nd : do all the date math and setting the values for the tags used in the templates

And it seems to work perfectly.


Now here are the details of what I’m trying to build :

I’m a bullet journal fan, so I’m trying to build a personal workflow in Drafts. I’m hoping that it will help others too, so of course I’ll be sharing it in the end.

In my workflow I’m using the daily log, the weekly log and the monthly log.

I’m currently using this action (made by you) to create a new Daily Log or a new Weekly Log based on a template Draft I’m having. But this limits me to only build a Draft for today/tomorrow and this week / next week (I have only these 4 templates).

So, to have something more generic that works in my case, I am currently building an action that can generate a Daily / Weekly / Monthly log based on a date you’re choosing.

Here’s the 'interface":

So, now, based on the date and the button pressed, it will generate a new Draft either for the selected date (a Daily), either for the week containing the selected date (a Weekly) or for the month containing the date (a Monthly).

And, because of this, I have to do some scripting, because using the [[date]] cannot respond at all my use-cases (or at least that’s what I think).

Here’s an example of my current Daily Log Template :

let templateNewDay = `# [[dateToday]]
→ 🗓 [[dateTodayName]]
→ Weekly Note : [[S[[dateWeekNumber]]]]
→ Future Log : [[FutureLog]]
<< [[[[dateYesterday]]]] | [[[[dateTomorrow]]]] >>


## Today's Tasks
- RAS

## Today's Events
@ RAS

## Tracking
- RAS

## Journal
- RAS`;

So, each type of log is, of course, different. As I’m hoping this will also be useful to other people in the future, I want to allow anyone to simply update these Log Templates and make them in their own way by adding what they’ll need by using the tags that will be available.

It’s still a WIP, but for now these are the tags it will support in the templates :

// Daily
- dateToday
- dateTodayName => customisable by the user
- dateWeekNumber
- dateYesterday
- dateTomorrow


// Weekly
- dateWeekNumber
- dateMonday
- dateSunday
- dateLastWeek
- dateNextWeek
- dateYear


// Monthly
- dateMonth
- dateMonthName => customisable by the user
- dateYear

For now it will only work for Mon-Sun weeks, but it can be easily adapted, in a second time, to also work with Sun-Sat weeks…

I don’t know if I explained well enough, but I know for sure that this will simplify my workflow and, besides, it allows me to code a little bit :stuck_out_tongue:

Thank you a lot for your message, and I’ll surely be back with other (maybe sometimes stupid) questions.

Oh, and thank you for building Drafts… :v:(-‿-):v: