Template styles

What a template style is

A template style is a named block of CSS that is injected into a document when it renders. Use styles to share a consistent look across many templates: fonts, heading colours, table borders, spacing, and branding. Define the style once and attach it to any template.

Template styles are stored as Template_Style__c records. Each has a Name and a Body (the CSS).

Attaching a style to a template

A template references one style through its style lookup. Set it on the Template, and every render of that template includes the style's CSS.

Scoping with the THIS keyword

Write selectors as normal CSS, and prefix them with THIS to scope them to the document body. THIS represents the document container, so the rule only affects this document and does not leak into the surrounding page.

The sample style that ships with a fresh install shows the pattern. It colours every heading red:

THIS h1, THIS h2, THIS h3, THIS h4, THIS h5, THIS h6 { color: red; }

Read THIS h1 as "an h1 inside this document". Follow the same pattern for tables, paragraphs, and any other element:

THIS table { border-collapse: collapse; }
THIS table td { border: 1px solid #ccc; padding: 6px; }
THIS p { line-height: 1.5; }

How styles combine

The template style is applied along with the document's page setup and margins. Standard CSS cascade rules apply, so more specific selectors win. Page size, orientation, and margins come from the template's settings and margins, not the style, so keep the style focused on look and feel.

Creating and managing styles

Manage styles from the Template Styles tab. Give each a clear Name and a CSS body. Because a style is shared by many templates, a small library of well-named styles (for example a house style, a formal-contract style) keeps documents consistent and easy to update.

Tips