TIP: Creating New Drafts with Templates

That’s pretty useful, thanks. A have a very dumb question, which language are these drafts scripts written in? Is it JavaScript?

Where do I change the ‘After Success’ for the Day One action? I use Day One from the share menu, I don’t have an action for it. If there is an action, please direct me so that I’ll use the action and not the share menu. Then what you’re saying will work.

Yes. Drafts’ JavaScript reference can be found here.

When editing an action you should see the options shown in my screenshot above.

There are videos on the actions documentation page that walk you through the basics around actions.

There is something called the Action Directory that is also linked to from the app when opting to create an action. The directory contains lots of actions that people have shared. You can search it for Day One to find ones related to your topic.

I imagine this one is probably the sort of thing you are after.

Each action in the directory has an option to install. Just tap it and follow the instructions to get the action deployed to your app.

Hope that helps.

That’s really useful! Because I know very little Javascript, I was struggling with the whole split/slice/join tango when it dawned on me that @agiletortoise had already done the heavy lifting with the [[body]] tag.
So I figured I’d take line 34:
let template = drafts[selectedIndex];
and simply add
template.content = template.processTemplate("[[body]]");
(well it took me a few tries figuring out how processTemplates really works …) It seems to me it does the same thing …

On a side note, is it me or are the terms templates and tags a little confusing now in Drafts. The templating engine takes tags (e.g. [[body]]) to process drafts into other drafts. But a tag can also be the label you attach to a draft, and a template can be a real template …

Something like:

template.content = template.processTemplate("[[line|2..]]");

would probably work if you didn’t want to mess with JavaScript. I wanted the extra flexibility being able to write body

Title
First line of content

and

Title

First line of content

without either skipping the first line (if I used “line|3…”) or including an extra blank line at the top of the output (if I used “line|2…”). Since the action was already using JavaScript, I figured it’d be easier to work in it directly.

I want to add different notes to different journals in the Day One app, how can I do that?

Amend the URL in the suggested action.

It starts as

dayone2://post?entry=[[draft]]

Using the URL scheme reference, it looks like you just append an extra parameter.

For example to save it to a “Daily Thoughts” journal, the URL would become.

dayone2://post?journal=Daily%20Thoughts&entry=[[draft]]

Hello,

I tried testing the template and the following template/drafts combination do not work as I expected:

template

ˋˋˋ

test template

[[date]]
[[line|2…]]
[[date]]

ˋˋˋ

draft

ˋˋˋ
Draft title
Line 1
Line 2
Line 3
ˋˋˋ

Result

ˋˋˋ

test template

2019-04-21

2019-04-21

ˋˋˋ

Am I missing something?

Thanks for your time!

Looks fine to me.

If you’re querying the line based template tag specifically, I’d query what it is supposed to be referencing when creating a new draft…

Also the title is equivalent to line 1, which might not match to your use of lines in your draft section.

Is something around that where your query lies?

Why is there nothing between the two date lines? I’d expect to see some of my draft line to show in the output…

As above. If you are just creating a new draft using a template, which is what the original post is about, then you wouldn’t have a source draft, so it would be expected you blank.

Think like new file from template in a Word Processor. It doesn’t use your existing document for anything.

If you are using templates against an existing draft, e.g. through an action against the current draft, then I would expect it to populate.

Think like scripting your word processor to build a new document from the currently open one.

If that still doesn’t explain things sufficiently, can you explain exactly how you are you using the “template” and template tags?

It all makes sense, thanks!

This what I am trying to do and I misunderstood the doc and the actual use of the macro. Will reread the doc more carefully…

I changed it as suggested by you, to be exact this is the syntax since I have a Thoughts journal

dayone2://post?entry=[[draft]]

dayone2://post?journal=Thoughts&entry=[[draft]]

The action failed

The URL in the error doesn’t match what you posted, it’s showing that it’s sending everything to entry. However without the full error message it’s hard to see what’s wrong.

Worked for me with a quick test.

Started with a draft containing multiple paragraphs of text.

I created this action and ran it against the Draft.

Day One opened, and populated the new entry in the journal.

Result in Drafts showed a success.

Maybe retry with my action above and see if that works? If not, can you share some sample Draft content that fails? Can then take a look at what might be going on in the content.

Many thanks, I’ll run your action. Could you amend the action for multiple Day One journals? Like if I have multiple drafts that go in different journals, the moment I initiate the action, I should get a choice of Day One journals to select. That’s what the ‘share’ menu does.

Yes. You could amend it to use a Drafts prompt to allow a choice of name. Just pre-populate it with the journal names you want to choose from and pass the encoded result in as the value of the journal parameter

I’m trying to run this script against an existing draft and was hoping that it would take the existing draft and populate it into a template. Is there a way to do that?

There are a number of scripts (and actions) discussed in the thread, so it isn’t clear which script you are referring to.

It is almost always better to start a brand new topic and reference/ (link back to) a previous topic rather than taking it on a tangent.

However, the focus of the discussion is on using pre-existing templates, or templates that you are building, rather than taking a draft and making it a template to select from.

The first post, includes an action from Greg whereby he uses other drafts marked with a tag of “template” to identify template drafts. Maybe you just want an action to tag a draft with that tag?