Configuration

Similarly to many other libraries, Squirrelly allows you to customize its behavior via options.

TypeDoc doc page

List of options

OptionDescriptionTypeDefaultRequired?
asyncWhether to generate async templatesbooleanfalseYes
autoEscapeWhether to automatically XML-escapebooleanYes
autoTrimConfigure automatic whitespace trimmingautoTrim[false, "nl"]Yes
cacheCache templates by name or filenamebooleanYes
defaultFilterPass all interpolates through a function`falseFunction`false
filenameAbsolute filepath of template (for caching)stringundefinedNo
lFunction that returns helpers. See lFunctiondefaultConfig.lYes
nameTemplate name (for caching)stringundefinedNo
pluginsPlugins objectpluginsdefaultConfig.pluginsYes
rootBase filepath. Defaults to "\" internallystringundefinedNo
storageObject containing templates, helpers, filtersstoragedefaultConfig.storageYes
tagsTemplate delimiters. CAVEATS[string, string]["{{", "}}"]Yes
useWithUse with(){} to have data scope as globalbooleanundefinedNo
varNameName of data objectstring"it"Yes
view cacheOverrides cachebooleanundefinedNo
viewsAbsolute filepath to views directorystringundefinedNo

Delimiter Caveats

Closing delimeters (like {{) can't have any of (, ), |, or =>.

Delimeters must be RegExp-escaped.

autoTrim

autoTrim controls whitespace trimming.

Signature

"nl" | "slurp" | boolean | ["nl" | "slurp" | boolean, "nl" | "slurp" | boolean]

Options

  • "nl" trims first character
  • "slurp" trims all leading/trailing whitespace
  • true is equivalent to "slurp"

When an array is passed, Squirrelly uses the equivalent options on the left or right side of the string

l

l is a function that is used inside template functions to fetch filters and helpers.

Signature

(container: "H" | "F", name: string) => Function

Default

function (container, name) {
if (container === 'H') {
var hRet = helpers.get(name)
if (hRet) {
return hRet
} else {
throw SqrlErr("Can't find helper '" + name + "'")
}
} else if (container === 'F') {
var fRet = filters.get(name)
if (fRet) {
return fRet
} else {
throw SqrlErr("Can't find filter '" + name + "'")
}
}
},

plugins

plugins is an object with the following properties:

PropertyDescriptionTypeDefault
processASTList of functions that manipulate Squirrelly syntax treeArray<object>[]
processFnStringList of functions that manipulate Squirrelly template functionArray<object>[]

storage

storage points to helpers, native helpers, filters, and templates. It's an object with the following properties:

PropertyDescriptionTypeDefault
filtersFilters cacheCacher<FilterFunction>Sqrl.filters
helpersHelpers cacheCacher<HelperFunction>Sqrl.helpers
nativeHelpersNative helpers cacheCacher<NativeHelperFunction>Sqrl.nativeHelpers
templatesTemplates cacheCacher<TemplateFunction>Sqrl.templates

You only need to modify it if you want to create environments with different caches.

defaultConfig

Sqrl.defaultConfig returns the default configuration. See above.

getConfig

getConfig takes some config options and merges them with the default. It optionally takes a third parameter, which it merges with the default first.

High-level APIs like render and compile call getConfig internally, but you should call lower-level APIs (like compileToString) with a valid config object, which you can get from this function.

Syntax

TypeDoc doc page

Example

Sqrl.compileToString(myTemplate, Sqrl.getConfig({ tags: ["<%", "%>"] }));