Building a template

A template is built on a canvas: folders and files laid out the way you want them on disk. What you see there is what gets created, so the quickest way to work is to build the folder you wish you already had.

The Prefab template editor with a folder tree on the canvas and the inspector panel on the right
The Prefab template editor with a folder tree on the canvas and the inspector panel on the right
The canvas holds the structure. The panel on the right shows whatever is selected.

The three tabs

The editor is split into three tabs, in the order most templates get built.

Structure is the canvas: the folders, the files, and the actions attached to them. This page is about that tab.

Placeholders is where you define what Prefab asks for at deploy time - the key, the label shown on the prompt, the type of field, a default value. See Using placeholders.

Automation holds the template's action definitions: initialise a git repository, open the folder in an editor, run a command, or a rule that keeps working on files added later. See Actions.

The toolbar

The floating toolbar along the bottom of the canvas holds everything that changes the template:

  • Folder and File each add one item
  • Template embeds another template here. See Templates inside templates
  • Import brings in files or a folder from disk. See Importing a folder
  • Action attaches an action to the one item you have selected. See Actions
  • The bin deletes the selection

The buttons to the right of those change what you are looking at rather than what the template holds. They are covered under Getting around a large template.

Adding folders and files

Where a new item lands depends on what is selected:

  • A folder is selected - the new item goes inside it, and the folder expands to show it
  • A file is selected, or nothing is - the new item goes to the top level

The item arrives named New Folder or new_file.txt with its name field already open, so you can type over it straight away. Names can hold placeholders: a folder named {{client_name}} comes out named after the client, as long as that placeholder is defined. See Using placeholders.

To add into a particular folder without selecting it first, hover its row and use the + menu, or right-click it. Both offer New Folder, New File, Import Files… and Import Folder…. Right-clicking anything, folder or file, also offers Add Action, Rename and Delete.

Two items in a folder cannot share a name

Adding an item and renaming one both check the folder's other names first, so a second Assets is saved as Assets 2. If a name comes back numbered, something beside it already had it. Anything that does slip through - two Quick Add clicks of the same shortcut, say - is numbered again at deploy, where the second copy lands as Assets 01.

Quick Add

Quick Add is a list of one-click shortcuts for the things you add most often - a README.md with its opening lines already written, a src folder, a Billing folder. It appears in the inspector when nothing is selected, and again in a selected folder's panel, where it adds into that folder.

The list is seeded from the Experience you chose when you first opened Prefab, and is yours from then on. Settings ▸ Experience has the full list, and each shortcut has its own editor: whether it Creates a folder or a file, the Name it gives what it creates, the Label on the button, a Description, an Icon, and for a file its Starting contents. You can add your own, reorder or remove ones you never use, or reset the list to the Experience's defaults. Once you have edited the list, changing Experience later leaves it alone.

The Quick Add list in the inspector, showing shortcuts for a readme, a gitignore and source folders
The Quick Add list in the inspector, showing shortcuts for a readme, a gitignore and source folders
Quick Add adds into the selected folder, or at the top level when nothing is selected.

Renaming an item

Double-click it on the canvas to rename it in place. Return commits the new name, Esc cancels, and clicking away commits it too. Rename is also in the right-click menu, and the inspector has a pencil beside the name.

Moving items around

Drag a card to move it:

  • Onto a folder - it moves inside that folder, which expands to show it
  • Onto a file - it moves alongside that file, into the same folder
  • Onto empty canvas - it moves out to the top level

Everything below a folder travels with it. A folder cannot be dropped into itself or into anything inside it, and that drop is refused rather than detaching the branch.

What the panel on the right shows

The panel is the inspector, and it changes with the selection - a folder, a file, an embedded template, an action. With nothing selected it shows a Template Overview instead: how many folders, files, placeholders and actions the template holds, with the Quick Add shortcuts underneath. Drag its inner edge to make it wider or narrower.

Leaving a file with unsaved changes

Switching tabs while a file's contents are half-edited asks whether to save first, rather than quietly discarding the text. The same prompt appears when you select something else. Only the editor's own Cancel button discards without asking.

Getting around a large template

Drag empty canvas to move the tree, and pinch on a trackpad to zoom. The canvas controls in the bottom right show the current zoom as a percentage, with buttons either side that step in and out. Beside them, Reset View returns to 100% at the origin, and Fit to Screen returns to 100% with the tree centred in the window. Each template remembers its own position and zoom, so a template you come back to opens where you left it.

When exactly one item is selected, a breadcrumb bar above the toolbar shows the path to it, which is what tells you where you are once the tree is deeper than the window.

The toolbar's magnifying glass reveals a search field that filters the tree by name, keeping a folder visible when something inside it matches. Sort redraws the tree in one of five orders: Folders First, Files First, Name (A-Z), Name (Z-A) or Group by Type. Expand All and Collapse All open or close every folder at once. None of these change the template, and none of them change the order things are created in - they change what you are looking at.

Working from the keyboard

With the canvas focused and no text field being edited:

  • ⌘ACtrl+A selects everything, and Ctrl-click adds one item to the selection
  • ⌘CCtrl+C, ⌘XCtrl+X and ⌘VCtrl+V copy, cut and paste items, subfolders included
  • Delete removes what is selected, along with any actions attached to it
  • ⌘ZCtrl+Z and ⇧⌘ZCtrl+Shift+Z undo and redo edits to the template

Pasting drops the items into the selected folder, or beside the selected file, or at the top level when the selection is empty. Actions attached to a folder do not travel with the copy, so a pasted branch arrives as structure alone.

While you are typing in a name field or in file contents, these go back to meaning what they normally mean in text. The full list is in Keyboard shortcuts.