Alstre
Try it
08 · Document templates

Editing template code

The source code view for unusual documents: your own styles, layouts and sections that the blocks do not offer. We explain when it is really worth using and what limits the print engine.

Where to turn it on

Above the editing area there is a Visual / HTML switch. The first option shows the document as it looks; the second — its source code.

Not the same as advanced mode
The Simple / Advanced switch controls something else: whether you can insert variables in addition to blocks. Only the HTML switch described here opens the source code.

In the visual view, blocks and variables are shown as embedded elements — they are filled with content when the printout is generated.

When it is worth it

Less often than it seems. Before you reach for code, check whether the element you need is already in the block library — blocks are maintained together with the system and keep up with changes in the contract by themselves.

Code makes sense for three things:

  • Brand guidelines compliance — specific colours, spacing and typefaces that you cannot set with switches.
  • A section the blocks do not offer — for example your own terms of trade or shop terms and conditions.
  • Layout fixes — column widths in the line items table, spacing before signatures, forcing a page break.

What you can do in code

  • Inline styles on an element, for example <div style="color:#005bbb">
  • Changing the table structure, colours and spacing
  • Your own sections and paragraphs outside blocks
  • Variables inserted anywhere, for example {{customer_name}}
  • Blocks as empty tags <div data-block="..."> — the content is inserted when printing
Conditions are not written by hand
A passage that depends on the type of buyer is inserted with a conditional block, in this mode too. Syntax such as {{#if}} will not work — it will be printed literally, braces included.

What the print engine will not do

The template goes to a browser that renders the PDF, so styles behave as they do on a web page. Four things, however, work differently:

No JavaScript
The document is static. Nothing recalculates or animates.
Styles inside only
Stylesheets loaded from external addresses may not load. Write everything inline on elements or in a style block in the template text.
Images with a full address
An image must have a full address or come from files uploaded in the company settings. A relative path will not work.
Page breaks
You control them with page-break-before: always and page-break-inside: avoid. The latter is worth applying to the line items table, so a row does not split across pages.

The document prints in A4 format with background colours preserved. The header and footer are separate parts of the template — the engine calculates their margin itself, so you do not have to guess it.

How to work safely

  • Check the preview after every change. An unclosed tag can throw the entire rest of the document out of place.
  • Look at both scenarios — private individual and business.
  • Do a test print to PDF. The on-screen preview does not show page breaks.
  • Make changes on a copy of the template. A new template from the same starting point takes a moment and lets you go back to a version that worked.
One template in code, the rest from blocks
A hand-edited template no longer benefits from the improvements we add to blocks. Keep in code only the document that really needs it, and leave the rest on blocks.