"Using Drafts Templates"

Template Basics

Drafts actions consist of “steps.” Action steps are available for a wide range of functions and services: Sending messages, mail, saving files, and much more. Regardless of the purpose of the step, any step that output information has some fields that allow you to control what text the step uses, and (with a few minor exceptions) use templates to dynamically generate that text.

If you have poked around in the action editor and wondered what some of those [[title]] and [[body]] things are, this article is for you.

Templates are plain text combined with tags. Consider tags placeholders for some piece of information you want to be inserted when the action is run. Drafts tags are identified by double square brackets ([[ ]]), surrounding the tag name and options. Most tags insert some content or meta data related to the current draft on which an action is being performed.

Common Content Tags

The tags that get the most use, and which you are likely to see as defaults in many action steps, are:

Take the “Copy” action, which ships with Drafts in the “Basic” action group. The action places the contents of the current draft in the clipboard. The action itself consists of one Clipboard action step, with the template [[draft]]. If you wanted an action that copied just the first line of the draft to the clipboard, you could change the template of the clipboard action step to [[title]].

The default “Mail” action, which ships with the app, uses the [[title]] tag for the subject line of the email, and [[body]] as the content of the email.

1%202019-01-31%2016-39-17
1%202019-01-31%2016-39-17

You can mix tags with static text in templates, so you could also have the template string Title: [[title]], which would produce the first line of the draft, with the prefix Title:.

There is a handy [[line|n]] tag that lets you extract individual or ranges of lines from the content of a draft. The line tag is an example of a tag with a formatting option, separated from the tag name by a | pipe character. In this case, that option takes line number (1 for the first, 2 for the second, etc.), or range, like 1..3 for first through the third line. If you omit the beginning or end line number, the range will assume beginning or end, so ..4 is the first four lines, and 5.. is the fifth line to the end of the draft. Negative indexes which count back from the end can also be used, so [[line|-1]] would get you just the last line.

The linke can be very useful in splitting up values from a draft into separate values. Say you want an action that saves to a folder in Dropbox, but you want to specify that in the draft itself. You could type the following draft:

My File Name
Personal
    
The content of the draft.
    
    
    
    
    
Then have an action configured with a [Dropbox action step](https://docs.getdrafts.com/docs/actions/steps/services#dropbox) using the following template values for its fields:
    
    
    
    
    
    
  * 
**Name**: [[line|1]].txt
    
    
    
  * 
**Path**: /[[line|2]]/
    
    
    
  * 
**Template**: [[line|3..]]
    
    
    
    
    
![1%202019-01-31%2016-42-01](https://forums.getdrafts.com/uploads/default/optimized/2X/7/749ea3cbd1093d34902dff048de0115e3a18de10_2_304x250.jpeg)
    
    
    
    
Using this action, on the draft sample text above would result in a file on Dropbox named “My File Name.txt” in the folder “Personal”, with the content “The content of the draft.”
    
    
    
    
## 
Date and Time Tags
    
    
    
    
Another commonly used set of tags are date-related tags. The available date tags are:
    
    
    
    
    
    
  * 
**[[date]]**: Current date, defaulting to the format %Y-%m-%d, which is equivalent to YYYY-MM-DD.
    
    
  * 
**[[created]]**: The date the current draft was created.
    
    
  * 
**2021-12-08**: The date the content of the current draft was last modified.
    
    
    
    
Each of these tags can also take a formatting string, after the | separator, using [strftime](https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man3/strftime.3.html) formatting. There are formatting characters to allow configuration of almost any possible date and time string - including year, month names, day names, and much more. The [Apple strftime reference](https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man3/strftime.3.html) has details on all the available options. A few commonly used format examples:
    
    
    
    
    
    
  * 
[[date|%Y-%m-%d]] : _Result:_ 2019-01-31
    
    
  * 
[[date|%I:%M %p]] : _Result:_ 06:19 PM
    
    
  * 
[[date|%d %B %Y %H:%M:%S]] : _Result:_ 31 January 2019 21:19:20
    
    
    
    
Dr. Drang wrote an [excellent blog post about date tags in Drafts](http://www.leancrew.com/all-this/2013/02/new-flexible-timestamps-in-drafts/) which is an excellent resource as well.
    
    
    
    
To test formats, we also recommend [strftime.net](http://strftime.net), an online format builder which previews the output of format strings.
    
    
    
    
The most common use case for date tags is timestamping when appending to a daily journal file, or starting a draft from a template.
    
    
    
    
## 
Additional Tags
    
    
    
    
Visit the [template tag reference](https://docs.getdrafts.com/docs/actions/templates) for a complete list of available built-in tags. Using tags you can access information like location data stored with a draft, its UUID and permalink, tags, and more.
    
    
    
    
## 
No Tags Required
    
    
    
    
Keep in mind that just because templates in actions can contain tags to dynamically insert text, they don’t need to. Many times you just want plain static text in a template to add boilerplate snippets,
    
    
    
    
## 
Special Template Markup
    
    
    
    
In addition to tags, there are a couple of special markup conventions used in templates for convenience, they are:
    
    
    
    
    
    
  * 
**%20** : Any text between double curly braces will be URL encoded for use in URL query parameters. This is typically used in [Open URL action steps](https://getdrafts.com/actions/steps/openurl) to properly encode text to be included in a URL.
    
    
  * 
**

** : Any text between double percent signs will be converted from Markdown to HTML using your default Markdown options. Useful when publishing to locations that want HTML input.

  * 
**<<textexpander-shortcut>>** _[iOS Only]_ : If you use [TextExpander](https://textexpander.com/), it is possible to dynamically expand a TextExpander snippet when a template is evaluated. Generally useful for snippets you do not want to be expanded until the action is run because they contain dates or other output which is time-sensitive. To expand a snippet in a template, wrap the snippet’s shortcut text in << >>.
    
    
    
    
## 
Conclusion
    
    
    
    
With just a few tweaks to templates, you can create an array of useful actions that save time and formatting.

-"Using Drafts Templates"