Create your own HTML template

In this tutorial you will learn how to create your own template for MacSnapper.

There is also a reference template, called clean.cshtml, available to start with.

The XML document

MacSnapper will produce a simple XML document when exporting a lesson.

The following XML document will be used as an example in this tutorial:

    <title>Open Accounts Preferences</title>
    <step position="1">
        <title>Open Preferences</title>
        <detail>Click "System preferences..."</detail>
    <step position="2">
        <title>Click Accounts</title>
        <title>Setting Permissions</title>
        <step position="1">
            <title>Open Terminal</title>

MacSnapper will produce an XML file for each lesson and will contain all sub lessons.

Anatomy of a template bundle

A MacSnapper template is a bundle (folder) and contains two essential files, lesson.html and Info.plist.

A folder with the extention *.cshtml and containing the above two files is sufficient to call it a template bundle. Also there are a few other folders which you create within your template bundle.

Contents of a template bundle

Regular HTML file with additional "tpl" directives. It must be a well formed XML file
a property list file containing meta information about the template
a thumbnail image of your template look. Preferred size is 150x100 pixels
your images used in the template (not the step images)
your stylesheet (*.css) files.
your stylesheet files. Each .css file will be listed as different style in MacSnapper. Add your stylesheet to this directory if you want to support different styles like colors, fonts, etc.
this folder will be copied to the output directory. Use it. It's yours.

The folders images, css, styles and assets will be copied to the export directory.

You must not create a template bundle from scratch. Instead, duplicate and rename the template clean.cshtml, which is a simple and complete template example.
If you want, you can design a lesson.html file with your preferred WYSIWYG editor, or use a text editor.

Where should I place my template bundle ?

MacSnapper will search for template bundles in its Application Support folder

/Users/<you>/Library/Application Support/MacSnapper/Templates/

MacSnapper will search also yor Desktop for templates. This is very handy for template developers


About Info.plist

Info.plist contains information about the template.

The following example is the Info.plist file of the "clean" template.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" 
<plist version="1.0">

Defined keys in Info.plist

Your company name (or any string value if you are just developing the template for yourself)
Template name. This is what the user will see.
A unique identifier. MacSnapper will manage you template using the id and not the template name.
Set this to true, if you want to display lesson and step detail texts using your own font definitions. Set this to false if you want MacSnapper to generate span tags with font definitions as defined by the user within the application. (Default is 'false')
A css filename without extension placed in the stylesheets directory. This is useful to define a default style sheet if you have multiple sheets. If you not define a default style, MacSnapper will use the first css file found in the stylesheets directory. If you don't have a css file in the stylesheets directory, the default stylesheet will be 'basic'.

Variables defined in templates

There are some variables which you can use in lesson.html

path to the export directory
path to the css directory
path to the styles directory
style name seelcted by user. This is the selected css filename without extension.
path to images directory

The next examples will show you the usage of these variables.

TPL directives

Kedisoft has developed some directives to construct XHTML by using the input XML data.

To add TPL directives, define the following namespace

<html xmlns:tpl="">

All directives are attributes. Example:

<h1 tpl:replace="title">A title to replace with</h1>

Following directives are available

tpl:replace = "xpath"
Replaces the content of an element with the result of the given xpath, applied on the source XML.

You can also combine multiple xpath directives in tpl:replace. Place all xpath directives between brackets.



Outside the brackets you can add static text.


"{@position}. {title}" -> "1. Open Preferences"

@position is an XML attribute and title is an XML element as defined in lesson-v1.xsd.

tpl:loop = "xpath"
Applies the node, where tpl:loop is placed, to all source XML nodes returned by the given xpath directive.


<div tpl:loop="step">
    <h1 tpl:replace="title">A title</h1>


    <h1>Open Preferences</h1>
    <h1>Click Accounts</h1>

xpath directives within a loop (like "title" in the above example) are relative to the nodes returned by tpl:loop="xpath"

tpl:attribute = "htmlattr:xpath"
With tpl:replace you can add content to an element. However, to add XHTML attributes you can use tpl:attribute.




<img tpl:attribute="src:image"/>


<img src="Open_preferences.png"/>

You can also combine xpath directives and static texts.


<img tpl:attribute="src:../steps/{image}"/>


<img src="../steps/Open_preferences.png"/>

You can add attributes when you design. These will be removed in the resulting XHTML file. However, it is very useful while you design your template.


<img src="dummy.png" tpl:attribute="src:../steps/{image}"/>


<img src="../steps/Open_preferences.png"/>
tpl:goto="label" and tpl:label="a name"
you can redirect the next output node by using tpl:goto. tpl:goto will set the next output node to the labeled node.


<div tpl:label="lesson-label">
    <h1 tpl:replace="title">Lesson title</h1>
    <h3>Sub lessons</h3>
    <div tpl:loop="lesson" tpl:goto="lesson-label"/>


    <h1>Open Accounts Preferences</h1>
    <h3>Sub lessons</h3>
        <h1>Setting Permissions</h1>
        <h3>Sub lessons</h3>
prevents the template from writing out an XHTML node. The <h2> tag in the above example will always be written out. We want to write the header for sub lessons only if sub lessons exist.


<h2 tpl:if="lesson">Sublesson</h3>

Use tpl:if to check

  • whether an element exists or not
  • or an element is empty
  • The step at position "2" in our example input XML file has an empty <detail> tag. To prevent the template from writing out empty <div> tags, we can use tpl:if

    <div class="step-detail" tpl:if="detail"> ... </div>


    Designing templates for MacSnapper is very easy. The clean template is almost a completed template and you can start designing you own template by modifying this template.

    If you have questions or suggestions, just .

    Thanks for reading.


    Mac OS X 10.6.8 or later

    Try now!

    Want to see how an
    export will look like?

    Live Demo