"Using Drafts Templates - Integration Guides - Drafts Community"

Template Basics

Drafts actions consist of “steps.” Action steps 115 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 28, 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.


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
The content of the draft.
Then have an action configured with a [Dropbox action step 20](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..]]
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:
**2022-08-17**: Current date, defaulting to the format %Y-%m-%d, which is equivalent to YYYY-MM-DD.
**2021-12-08**: The date the current draft was created.
**[[modified]]**: 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 182](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 182](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 499](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 55](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 170](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 86](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 55. Useful when publishing to locations that want HTML input.

**<<textexpander-shortcut>>** _[iOS Only]_ : If you use [TextExpander 40](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 << >>.
With just a few tweaks to templates, you can create an array of useful actions that save time and formatting.
  * [TIP: Creating New Drafts with Templates505](https://forums.getdrafts.com/t/tip-creating-new-drafts-with-templates/4253/4)
  * [Preview templates201](https://forums.getdrafts.com/t/preview-templates/4118/4)
  * [How / where would i look to understand [[draft]]?39](https://forums.getdrafts.com/t/how-where-would-i-look-to-understand-draft/5073/4)
  * [Sending Mail with Drafts26](https://forums.getdrafts.com/t/sending-mail-with-drafts/3597)
  * [Version History6](https://forums.getdrafts.com/t/version-history/4575/2)
  * 21 more

-"Using Drafts Templates - Integration Guides - Drafts Community"