Skip to main content

Directive Reference

A directive is a comment that starts with CodeBaker:. CodeBaker removes the comment, and what follows CodeBaker: takes its place, or is carried out as a command. This page lists every word that can follow it, with a link to the page that explains it. For a first look, read Keeping the Template Valid for Your IDE.


What can follow CodeBaker:​

After CodeBaker:What happensExplained in
A Pebble tag, for example {% if x %}The tag takes the place of the commentKeeping the Template Valid for Your IDE
Any other text, for example background: ___color___;The text takes the place of the comment, so the IDE sees a comment and the generated file gets the lineKeeping the Template Valid for Your IDE
replace <value> => <replacement> [#tag]A rule: swaps the value, on this line if the comment trails code, or from this line down if it stands aloneReplacing Real Values
regex <pattern> => <replacement> [#tag]The same, with a Java regular expressionReplacing Real Values
off <value or #tag> ... and on <value or #tag> ...Pauses and resumes the rules that matchReplacing Real Values
resetRemoves every rule declared so farReplacing Real Values
separatorBecomes {% if not loop.last %},{% endif %}: a comma between the items of a loopGenerating JSON
{% slot name %}, {% endslot %}, {% fragment id %}, {% endfragment %}Slot markers for insert and replace: copied into the generated file exactly as writtenSeed, Insert and Replace
{% raw %}, {% endraw %}, {% verbatim %}, {% endverbatim %}A raw block: the comment around the tag is removed first, and what is inside is never read or changedEscaping Text

Where you can write one​

PrefixLanguages
//PHP, Java, Kotlin, JavaScript, TypeScript, Go, SCSS, LESS
/* ... */CSS and C-style block comments: write /* CodeBaker: ... */
#Python, Ruby, shell, YAML
--SQL, Lua
<!-- ... -->HTML, XML, Markdown

A closing */ or --> is optional and is removed too. // is not a comment in plain CSS or in a <style> block.


Rules for every directive​

  • The directive is the last thing on its line. It runs to the end of the line.
  • CodeBaker: needs the colon and exactly that case. // CodeBaker is a tool, // see CodeBaker: docs and // codebaker: x are ordinary comments.
  • The first word after CodeBaker: is reserved when it is replace, regex, on, off or reset: it is a command, not text.
  • A line that holds only tags leaves no empty line. Its tags join the next line, which keeps its own indentation. The text that replaces a full-line comment starts at the beginning of the line.
  • A rule works from its line downwards, once. It never changes the lines above it and needs no closing line.
  • A directive that CodeBaker cannot parse is not an error. A replace with no replacement, for example, stays in the generated file as text.
  • A directive inside a raw block is only text. Nothing in a raw block is read.
  • With another syntax, the tags are written with its delimiters: <!-- CodeBaker: [% if x %] --> for square.

The order in which directives, rules, placeholders and Pebble are applied to a file is in How One File Is Processed.