Default Filters

The default filters are a comprehensive suite of safe filters useful within a View Engine or Text Template Generation environment. The source code for all default filters are defined in TemplateDefaultFilters.

For examples of querying with filters checkout the Live LINQ Examples, we'll show examples for other useful filters below:

Filters as bindings

Filters with no arguments can be used in-place of an argument binding, now and utcNow are examples of this:

Many filters have an implicit default format which can be overridden in the TemplateContext's Args, e.g if no Date Format is provided it uses the default format yyyy-MM-dd which can be overridden with:

var context = new TemplateContext {
    Args = {
        [TemplateConstants.DefaultDateFormat] = "yyyy-MM-dd HH:mm:ss"

HTML Encoding

All values of Template Expressions in .html pages are HTML-encoded by default, you can bypass the HTML encoding to emit raw HTML by adding the raw filter as the last filter in an expression:


Templates supports the same arithmetic expressions as JavaScript:

Behavior is as you would expect in JavaScript except for Bitwise OR | needs to be in (parens) to avoid it being treated as a filter expression separator and no assignment operations are supported, i.e. =, ++, --, |=, etc. The = is treated as an equality operator == so it lets you use SQL-like queries if preferred, e.g. a = 1 and b = 2 or c = 3 .

For those who prefer wordier descriptions, you can use the equivalent built-in filters:

It should be noted when porting C# code that as filters are normal methods they don't follow the implied Order of Operations used in math calculations where an expression like 1 - 2 + 3 * 4 / 5 is executed in the implied order of (1 - 2) + ((3 * 4) / 5). To achieve the same result you'd need to execute them in their implied grouping explicitly:


Most Math APIs are available including pi and e constants:

Date Functions


Use format filters to customize how values are formatted:

When no format provided, the default TemplateConstant's formats are used:

String functions

As can be expected from a templating library there's a comprehensive set of string filters available:

Text Style

Trimming and Padding

URL handling

Repeating, Ranges and Generation


The following filters can be used to easily control the precise spacing in templates:

The default spacing used for indents \t can be overridden with the Args[DefaultIndent].

Conditional Tests

These filters allow you to test for different conditions:

Object Type Tests

Filters to check the type of objects:

Object Conversions

Conversions and transformations between different types:

Conditional Display

These filters can be used in combination with Conditional Test filters above to control what text is displayed:

Content Handling

Control Execution

The end* filters short-circuits the execution of a filter and discard any results. They're useful to use in combination with the use* filters which discards the old value and creates a new value to be used from that point on in the expression. show is an alias for use that reads better when used at the end of an expression.

You can also use end to discard return values of filters with side-effects, block filters, partials, etc. It also provides an easy way to comment out any expression by prefixing it at the start, e.g: {{ end | unreachable }}

The ifUse and useIf filters are the inverse of the end* filters where they continue execution with a new value if the condition is true:

There's also an only* filter for each end* filter above with the inverse behavior, e.g:


You can create temporary arguments within a templates scope or modify existing arguments with:

Let Bindings and Scope Vars

Let bindings allow you to create scoped argument bindings from individual string expressions:

scopeVars lets you create bindings from a Dictionary, List of KeyValuePair's or List of Dictionaries using the key as the name of the argument binding and the value as its value:

Querying Objects

Member Expressions

JavaScript member expressions are supported except for calling methods on instances as only registered filters can be invoked.

Mapping and Conversions

Use map when you want to transform each item into a different value:

It's also useful for transforming raw data sources into more manageable ones:

Whilst these filters let you perform some other popular conversions:

Use parseKeyValueText to convert a key/value string into a dictionary, you can then use values and keys to extract the Dictionaries keys or values collection:


Use the json filter when you want to make your C# objects available to the client JavaScript page:

Embedding in JavaScript

You can use the filters below to embed data on the client in JavaScript. If it's a valid JS Object or JSON it can be embedded as a native data JS structure without quotes, otherwise use jsString to capture it in a JavaScript string variable:

The JSV Format is great when you want a human-friendly output of an object graph, you can also use dump if you want the JSV output indented:

If needed, the csv and xml serialization formats are also available:


By default the evalTemplate filter renders Templates in a new TemplateContext which can be customized to utilize any additional plugins, filters and blocks available in the configured TemplatePagesFeature, or for full access you can use {use:{context:true}} to evaluate any Template content under the same context that evalTemplate is run on.

E.g. you can evaluate dynamic Template Syntax which makes use of the MarkdownTemplatePlugin plugin with:

{{ content | evalTemplate({use:{plugins:'MarkdownTemplatePlugin'}}) | raw }}

This filter is used by the /preview.html API Page to create an API that enables live previews.


The select filter and its inverse forEach are the primary way to generate custom output for each item in a collection:

Use step if you want to iterate using a custom step function:


Use #raw block filter or pass to emit a Template Expression without evaluating it:

Useful when you want to emit a client-side Vue filter or show examples of Template Expressions.

of will let you find values of a specified type:

You can use appSetting filter to access the value of the TemplateContext's configured AppSettings Provider:

{{ 'websitePublicUrl' | appSetting }} 

Collections and Querying

Checkout the Live LINQ examples to explore the various collection and querying features.

Filter API Reference

See the Filter API Reference for the full list of default filters available.

made with by ServiceStack