<html><head><title>File Templates</title><link rel="stylesheet" href="help:/common/kde-default.css" type="text/css"><link rel="stylesheet" href="help:/common/kde-docs.css" type="text/css"><link rel="stylesheet" href="help:/common/kde-localised.css" type="text/css"><meta name="generator" content="DocBook XSL Stylesheets V1.67.2"><meta name="keywords" content="KDE, kdebase, Kate, text, editor, programmer, programming, projects, MDI, Multi, Document, Interface, terminal, console"><link rel="start" href="index.html" title="The Kate Handbook"><link rel="up" href="plugins.html" title="Chapter 5. Working with Plugins"><link rel="prev" href="kate-application-plugins.html" title="Kate Application Plugins"><link rel="next" href="kate-application-plugin-xmlcheck.html" title="XML Validation"><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta name="GENERATOR" content="KDE XSL Stylesheet V1.14 using libxslt"></head><body><div id="content" bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div id="header"><div id="header_content"><div id="header_left"><div id="header_right"><img src="help:/common/top-kde.jpg" width="36" height="34"> File Templates</div></div></div></div><div class="navCenter"><table class="navigation"><tr><td class="prevCell"><a accesskey="p" href="kate-application-plugins.html">Prev</a></td><td class="upCell">Working with Plugins</td><td class="nextCell"><a accesskey="n" href="kate-application-plugin-xmlcheck.html">Next</a></td></tr></table></div><div id="contentBody"><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="kate-application-plugin-filetemplate"></a>File Templates</h2></div><div><div class="authorgroup"><p class="author"><span class="firstname">Anders</span> <span class="surname">Lund</span> </p></div></div></div></div><p>The File Templates plugin allows you to create files based on other
files.</p><p>When you first install Kate, you need to enable the plugin:</p><div class="orderedlist"><ol type="1"><li><p>
Click <span xmlns:doc="http://nwalsh.com/xsl/documentation/1.0" class="guiitem"><span class="guimenu">Settings</span></span>-><span xmlns:doc="http://nwalsh.com/xsl/documentation/1.0" class="guiitem"><span class="guimenuitem">Configure Kate</span></span>
</p></li><li><p>
In the tree on the left of the screen, click <span xmlns:doc="http://nwalsh.com/xsl/documentation/1.0" class="guiitem"><span class="guilabel">Plugins</span></span>.
</p></li><li><p>
In the <span xmlns:doc="http://nwalsh.com/xsl/documentation/1.0" class="guiitem"><span class="guilabel">Plugin Manager</span></span> panel on the right, select <span xmlns:doc="http://nwalsh.com/xsl/documentation/1.0" class="guiitem"><span class="guilabel">File Templates</span></span>, and then click <span xmlns:doc="http://nwalsh.com/xsl/documentation/1.0" class="guiitem"><span class="guibutton">OK</span></span>.
</p></li></ol></div><p>You can now use any file as a template (this creates a copy of the
file with an empty <span class="acronym">URL</span>.) Special template files can contain
macros to fill in information such as your name, email address, the
current date, and position the cursor at a
convenient position in the new file.</p><p>You can easily create a new template from an open document.</p><p>Templates that you save to the template folder are
listed under the menu item <span xmlns:doc="http://nwalsh.com/xsl/documentation/1.0" class="guiitem"><span class="guimenu">File</span></span>-><span xmlns:doc="http://nwalsh.com/xsl/documentation/1.0" class="guiitem"><span class="guimenuitem">New from
Template</span></span>.</p><p>The template folder is part of the <span class="acronym">KDE</span> file system, and
consists of at least</p><div class="itemizedlist"><ul type="disc"><li><p>
         <code class="filename">$<span xmlns:doc="http://nwalsh.com/xsl/documentation/1.0" class="envar"><code class="envar">KDEDIR</code></span>/share/applications/kate/plugins/katefiletemplates/templates</code>
        </p></li><li><p>
<code class="filename">$<span xmlns:doc="http://nwalsh.com/xsl/documentation/1.0" class="envar"><code class="envar">KDEHOME</code></span>/share/applications/kate/plugins/katefiletemplates/templates.</code>
        </p></li></ul></div><p>If your <span xmlns:doc="http://nwalsh.com/xsl/documentation/1.0" class="envar"><code class="envar">KDEDIRS</code></span> environment variable contains additional directories, those are
searched for a similar subdirectory as well. If equally named templates are
found, the one in the local (KDEHOME) folder is chosen.</p><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="katefiletemplates-menu"></a>Menu Structure</h3></div></div></div><div class="variablelist"><dl><dt><span class="term">
<span xmlns:doc="http://nwalsh.com/xsl/documentation/1.0" class="guiitem"><span class="guimenu">File</span></span>-><span xmlns:doc="http://nwalsh.com/xsl/documentation/1.0" class="guiitem"><span class="guisubmenu">New From Template</span></span>-><span xmlns:doc="http://nwalsh.com/xsl/documentation/1.0" class="guiitem"><span class="guimenuitem">Any File...</span></span>
</span></dt><dd><p>Presents you with Open File dialog that allows
you to use any file as a template. If the chosen file has the
extension <code class="filename">katetemplate</code> it will be parsed
for template information and macros.</p></dd><dt><span class="term">
<span xmlns:doc="http://nwalsh.com/xsl/documentation/1.0" class="guiitem"><span class="guimenu">File</span></span>-><span xmlns:doc="http://nwalsh.com/xsl/documentation/1.0" class="guiitem"><span class="guimenuitem">New From Template</span></span>
</span></dt><dd><p>The remainder of submenus contains links to
templates. Click a menuitem to create a file as described by
the menu item text.</p></dd><dt><span class="term">
<span xmlns:doc="http://nwalsh.com/xsl/documentation/1.0" class="guiitem"><span class="guimenu">Settings</span></span>-><span xmlns:doc="http://nwalsh.com/xsl/documentation/1.0" class="guiitem"><span class="guimenuitem">Manage
Templates...</span></span></span></dt><dd><p>This will launch a dialog with a list of all templates
found within the template directories, along with options to add,
edit or remove templates.</p></dd></dl></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="katefiletemplates-use"></a>Using a <span class="application">Kate</span> Template</h3></div></div></div><p>When creating a file from a template that contain template
macros, some macros appears as editable variables in the text. Such
variables appears as underlined words in the text.</p><p>The first variable will be selected, so you just have to type to edit
it.If the document text contains more instances of the same variable,
they are changed as you edit. To move to the next editable variable,
press the TAB key. When the last variable is edited, the list is
dropped, and your TAB key works as normal.</p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="katefiletemplates-create"></a>Creating your own templates</h3></div></div></div><p>To create a new template, use the
<span xmlns:doc="http://nwalsh.com/xsl/documentation/1.0" class="guiitem"><span class="guimenu">Settings</span></span>-><span xmlns:doc="http://nwalsh.com/xsl/documentation/1.0" class="guiitem"><span class="guimenuitem">Manage Templates</span></span> Item to launch
the template management dialog. In that, click
<span xmlns:doc="http://nwalsh.com/xsl/documentation/1.0" class="guiitem"><span class="guibutton">New...</span></span> to launch the File Template Wizard. You
will be asked for an optional file to turn into a template and prompted
for template information settings, and a template file will be created for
you.</p><p>Alternatively, you can create a template manually by
adding template information to the top of any file, add text and macros,
and save it with the <code class="filename">katetemplate</code> extension.</p><p>The template menu gets automatically updated if you chose to store
your template in the template directory.</p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="katefiletemplates-edit"></a>Editing templates</h3></div></div></div><p>To edit a template, use the
<span xmlns:doc="http://nwalsh.com/xsl/documentation/1.0" class="guiitem"><span class="guimenu">Settings</span></span>-><span xmlns:doc="http://nwalsh.com/xsl/documentation/1.0" class="guiitem"><span class="guimenuitem">Manage Templates...</span></span>. Select the
template you want to work on and click <span xmlns:doc="http://nwalsh.com/xsl/documentation/1.0" class="guiitem"><span class="guibutton">Edit...</span></span>,
and the template file will be opened. Close the dialog, edit the template
file as desired, save it and close it. Changes to templates takes
immediate effect, you can activate the template to test your changes after
saving it.</p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="katefiletemplates-format"></a>The <span class="application">Kate</span> Template Format</h3></div></div></div><p>If you use files with the extension
<code class="filename">katetemplate</code>, they will be parsed for template
information, macros and a cursor position.</p><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="katefiletemplates-template-info"></a>Template information</h4></div></div></div><p>While reading in the file, the parser keeps
lines beginning with the phrase
<code class="constant">katetemplate:</code> and searches them for
template information in the form VARIABLENAME=VALUE. The first line not
starting with <code class="constant">katetemplate:</code> will be taken as the
start of the template contents. VALUE may contain any character but
equal sign (=). Legal variable names are:
<div class="variablelist"><dl><dt><span class="term"><code class="varname">Template</code></span></dt><dd><p>This is the template name, displayed in the
<span xmlns:doc="http://nwalsh.com/xsl/documentation/1.0" class="guiitem"><span class="guimenu">File</span></span>-><span xmlns:doc="http://nwalsh.com/xsl/documentation/1.0" class="guiitem"><span class="guimenuitem">New from
Template</span></span> menu.</p></dd><dt><span class="term"><code class="varname">Group</code></span></dt><dd><p>The group places the template in a submenu of
the <span xmlns:doc="http://nwalsh.com/xsl/documentation/1.0" class="guiitem"><span class="guimenu">File</span></span>-><span xmlns:doc="http://nwalsh.com/xsl/documentation/1.0" class="guiitem"><span class="guimenuitem">New from
Template</span></span> menu.</p></dd><dt><span class="term"><code class="varname">Name</code></span></dt><dd><p>This is the name that will be set for the
document, and displayed in the file list and title bar. If the
name contains <strong class="userinput"><code>%N</code></strong> that will be replaced
with a number, increasing if more documents has the same
name.</p></dd><dt><span class="term"><code class="varname">Highlight</code></span></dt><dd><p>The plug-in will try to set the Highlight for
the new document to the value of this variable. The value
should be the name, as found in the
<span xmlns:doc="http://nwalsh.com/xsl/documentation/1.0" class="guiitem"><span class="guimenu">Tools</span></span>-><span xmlns:doc="http://nwalsh.com/xsl/documentation/1.0" class="guiitem"><span class="guimenuitem">Highlighting</span></span>.</p></dd><dt><span class="term"><code class="varname">Description</code></span></dt><dd><p>A short informative description of the
template. This is currently used to set a Whatsthis string for
the menu item, but may be used for more purposes in the
future.</p></dd><dt><span class="term">Author</span></dt><dd><p>A string identifying the author, for example
in the form <strong class="userinput"><code>Name <email address></code></strong>.
This is currently used to set a Whatsthis string for the menu
item, but may be used for more purposes in the
future.</p></dd></dl></div>
</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="katetemplates-macros"></a>Template Macros</h4></div></div></div><p>While parsing the template contents, macros in the form
<strong class="userinput"><code>%{NAME}</code></strong> or <strong class="userinput"><code>${NAME}</code></strong> are
expanded. If you use the <strong class="userinput"><code>$</code></strong> prefix, the
expanded macro will be treated as a editable variable when a document
is created from the template, whereas if you use
<strong class="userinput"><code>%</code></strong> it is not, unless expanding failed.</p><p>The following macros are expanded:
<div class="variablelist"><dl><dt><span class="term">time</span></dt><dd><p>Expands to the current time in your locale
format.</p></dd><dt><span class="term">date</span></dt><dd><p>Expands to the current date in short
format.</p></dd><dt><span class="term">datetime</span></dt><dd><p>Expands to the current date and time,
formatted as a string according to your
locale.</p></dd><dt><span class="term">year</span></dt><dd><p>The current year as a four digit
number.</p></dd><dt><span class="term">month</span></dt><dd><p>The full name of the current month, according
to your locale.</p></dd><dt><span class="term">day</span></dt><dd><p>Expands to the current day of the month.</p></dd><dt><span class="term">hostname</span></dt><dd><p>Expands to the 'hostname' of your computer.</p></dd><dt><span class="term">index</span></dt><dd><p>Expands to 'i'.</p></dd><dt><span class="term">fullname</span></dt><dd><p>Expands to your full name, as defined by the
owner addressee in your standard <span class="acronym">KDE</span>
addressbook.</p></dd><dt><span class="term">firstname</span></dt><dd><p>Expands to your first name, as defined in the owner
addressee in your standard <span class="acronym">KDE</span> addressbook.</p></dd><dt><span class="term">lastname</span></dt><dd><p>Expands to your last name, as defined in the owner
addressee in your standard <span class="acronym">KDE</span> addressbook.</p></dd><dt><span class="term">email</span></dt><dd><p>Expands to your email address, as defined by
the owner address in your standard <span class="acronym">KDE</span>
addressbook.</p></dd></dl></div>
</p><p>Any macro not in the above list is treated as a editable variable
no matter the prefix.
If the same variable occurs multiple times in the template, they can be
edited at once after creating a document from the template.</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="katefiletemplates-cursor"></a>Setting the cursor position</h4></div></div></div><p>The special macro <strong class="userinput"><code>${cursor}</code></strong> will be replaced
with a vertical bar and added to the end of the list of editable variables,
independent on its location in the text.</p></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2745069"></a>Thanks and Acknowledgments</h3></div></div></div><p>
<span class="application">Kate</span> Plugin “<span class="quote">File Templates</span>” copyright 2004 <span class="firstname">Anders</span> <span class="surname">Lund</span>
<code class="email">(anders AT alweb.dk)</code>.
</p><p>Documentation copyright 2004 <span class="firstname">Anders</span> <span class="surname">Lund</span></p></div></div></div><div id="footer"><div class="navCenter"><table class="navigation"><tr><td class="prevCell"><a accesskey="p" href="kate-application-plugins.html">Prev</a></td><td class="upCell"><a accesskey="h" href="index.html">Contents</a></td><td class="nextCell"><a accesskey="n" href="kate-application-plugin-xmlcheck.html">Next</a></td></tr><tr><td class="prevCell"><span class="application">Kate</span> Application Plugins </td><td class="upCell">Working with Plugins</td><td class="nextCell"> <span class="acronym">XML</span> Validation</td></tr></table></div><div id="footer_text">Would you like to make a comment or contribute an update to this page?<br>Send feedback to the <a href="mailto:kde-doc-english@kde.org" class="footer_email">KDE Docs Team</a></div></div></div></body></html>