Files
org-roam/manual/Org_002droam-Template-Expansion.html
2020-05-13 11:45:38 +00:00

110 lines
5.4 KiB
HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- Copyright (C) 2020-2020 Jethro Kuan <jethrokuan95@gmail.com>
You can redistribute this document and/or modify it under the terms
of the GNU General Public License as published by the Free Software
Foundation, either version 3 of the License, or (at your option) any
later version.
This document is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
-->
<!-- Created by GNU Texinfo 6.5, http://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Org-roam Template Expansion (Org-roam User Manual)</title>
<meta name="description" content="Org-roam Template Expansion (Org-roam User Manual)">
<meta name="keywords" content="Org-roam Template Expansion (Org-roam User Manual)">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<link href="index.html#Top" rel="start" title="Top">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="The-Templating-System.html#The-Templating-System" rel="up" title="The Templating System">
<link href="Concepts-and-Configuration.html#Concepts-and-Configuration" rel="next" title="Concepts and Configuration">
<link href="Template-Walkthrough.html#Template-Walkthrough" rel="prev" title="Template Walkthrough">
<style type="text/css">
<!--
a.summary-letter {text-decoration: none}
blockquote.indentedblock {margin-right: 0em}
blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
blockquote.smallquotation {font-size: smaller}
div.display {margin-left: 3.2em}
div.example {margin-left: 3.2em}
div.lisp {margin-left: 3.2em}
div.smalldisplay {margin-left: 3.2em}
div.smallexample {margin-left: 3.2em}
div.smalllisp {margin-left: 3.2em}
kbd {font-style: oblique}
pre.display {font-family: inherit}
pre.format {font-family: inherit}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
pre.smalldisplay {font-family: inherit; font-size: smaller}
pre.smallexample {font-size: smaller}
pre.smallformat {font-family: inherit; font-size: smaller}
pre.smalllisp {font-size: smaller}
span.nolinebreak {white-space: nowrap}
span.roman {font-family: initial; font-weight: normal}
span.sansserif {font-family: sans-serif; font-weight: normal}
ul.no-bullet {list-style: none}
-->
</style>
</head>
<body lang="en">
<a name="Org_002droam-Template-Expansion"></a>
<div class="header">
<p>
Previous: <a href="Template-Walkthrough.html#Template-Walkthrough" accesskey="p" rel="prev">Template Walkthrough</a>, Up: <a href="The-Templating-System.html#The-Templating-System" accesskey="u" rel="up">The Templating System</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<hr>
<a name="Org_002droam-Template-Expansion-1"></a>
<h3 class="section">5.2 Org-roam Template Expansion</h3>
<p>Org-roam&rsquo;s template definitions also extend org-capture&rsquo;s template syntax, to
allow prefilling of strings. We have seen a glimpse of this in <a href="Template-Walkthrough.html#Template-Walkthrough">Template
Walkthrough</a>.
</p>
<p>In org-roam templates, the &lsquo;<samp>${var}</samp>&rsquo; syntax allows for the expansion of
variables, stored in &lsquo;<samp>org-roam-capture--info</samp>&rsquo;. For example, during
&lsquo;<samp>org-roam-insert</samp>&rsquo;, the user is prompted for a title. Upon entering a
non-existent title, the &lsquo;<samp>title</samp>&rsquo; key in &lsquo;<samp>org-roam-capture--info</samp>&rsquo; is set to the
provided title. &lsquo;<samp>${title}</samp>&rsquo; is then expanded into the provided title during the
org-capture process. Any variables that do not contain strings, are prompted for
values using &lsquo;<samp>completing-read</samp>&rsquo;.
</p>
<p>After doing this expansion, the org-capture&rsquo;s template expansion system
is used to fill up the rest of the template. You may read up more on
this on <a href="https://orgmode.org/manual/Template-expansion.html#Template-expansion">org-capture&rsquo;s documentation page</a>.
</p>
<p>To illustrate this dual expansion process, take for example the template string:
&lsquo;<samp>&quot;%&lt;%Y%m%d%H%M%S&gt;-${title}&quot;</samp>&rsquo;, with the title &lsquo;<samp>&quot;Foo&quot;</samp>&rsquo;. The template is first
expanded into &lsquo;<samp>%&lt;%Y%m%d%H%M%S&gt;-Foo</samp>&rsquo;. Then org-capture expands &lsquo;<samp>%&lt;%Y%m%d%H%M%S&gt;</samp>&rsquo;
with timestamp: e.g. &lsquo;<samp>20200213032037-Foo</samp>&rsquo;.
</p>
<p>All of the flexibility afforded by Emacs and Org-mode are available. For
example, if you want to encode a UTC timestamp in the filename, you can take
advantage of org-mode&rsquo;s &lsquo;<samp>%(EXP)</samp>&rsquo; template expansion to call &lsquo;<samp>format-time-string</samp>&rsquo;
directly to provide its third argument to specify UTC.
</p>
<div class="lisp">
<pre class="lisp">(&quot;d&quot; &quot;default&quot; plain (function org-roam--capture-get-point)
&quot;%?&quot;
:file-name &quot;%(format-time-string \&quot;%Y-%m-%d--%H-%M-%SZ--${slug}\&quot; (current-time) t)&quot;
:head &quot;#+TITLE: ${title}\n&quot;
:unnarrowed t)
</pre></div>
</body>
</html>