Miscellaneous Filters These are provided in the default filters. Specifically, when TemplateOptions is constructed, these are added via the extension method WithMiscFilters. default MethodMiscFilters.Default Returns a “default value” if the input is not invalid, which means a NilValue, an EmptyValue, or a boolean false. The default value is the first argument. Liquid {{ "" | default:"Deane" }} {{ "Annie" | default:"Deane" }} {{ false | default:"Deane" }} Output Deane Annie Deane You can pass in a named argument of allow_false:true and boolean false values will be considered valid. date MethodMiscFilters.Date Formats a date. This uses the Liquid syntax, not the C# syntax. If you want to use C# formatting syntax (which will not be Liquid-compliant), use format_date (see below). Here is a table of the Liquid date formatting. The input must parse as a DateTime, and the argument is required. Liquid {{ "2021-12-09" | date:"%A, %B %e, %Y" }} Output Thursday, December 9, 2021 (Note the day represented by %e is space-padded, hence the extra space after the month.) There are some handy “roll-ups”: %c = “Thursday, 09 December 2021 00:00:00” (note that example input had no time specified) %D = “12/09/21” %F = “2021-12-09” %s = “1639029600” (number of seconds since the epoch, which is helpful for JavaScript) raw MethodMiscFilters.Raw compact MethodMiscFilters.Compact Removes “nil” values from arrays. Specifically, it iterates the input array, calls IsNil() on all values, and returns a new array of only those values which returned false At the default installation, this is only NilValue, BlankValue, and EmptyValue. Everything other value – including empty strings and boolean false values – will return false from IsNil() which is the default non-overridden behavior from the FluidValue base class (outside of the three mentioned above, none of the other derived classes override the method). url_encode MethodMiscFilters.UrlEncode Encodes special characters in strings according to standard URL encoding. (RFCs 3986 and 3987) Liquid {{ "/page?a=b" | url_encode }} Output %2Fpage%3Fa%3Db url_decode MethodMiscFilters.UrlDecode Decodes encoded special characters to their ASCII intentions. Liquid {{ "%2Fpage%3Fa%3Db" | url_decode }} Output /page?a=b base64_encode MethodMiscFilters.Base64Encode Base64 encodes a string. Empty strings will Liquid {{ "Deane" | base64_encode }} Output RGVhbmU= base64_decode MethodMiscFilters.Base64Decode Base64 decodes a string. Liquid {{ "RGVhbmU=" | base64_decode }} Output Deane base64_url_safe_encode MethodMiscFilters.Base64UrlSafeEncode Same as base64_decode but it replaces + with - and / with _ so the value can be safely passed in a URL. base64_url_safe_decode MethodMiscFilters.Base64UrlSafeDecode Decodes a value created by base64_url_safe_decode. strip_html MethodMiscFilters.StripHtml Removes anything between < and >, inclusive. Liquid {{ "<p>Deane</p>" | strip_html }} Output Deane It doesn’t parse or lex the HTML, it literally just iterates all the characters and concatenates anything outside of brackets. escape MethodMiscFilters.Escape Escapes HTML – converts brackets to entities. Liquid {{ '<p>Deane</p>' | escape }} Output <p>Deane</p> escape_once MethodMiscFilters.EscapeOnce handle / handleize MethodMiscFilters.Handleize json MethodMiscFilters.Json Serializes the object to JSON. Works with all FluidTypes. An array will serialize each individual element. C# people.Add(new Person() { FirstName = "Deane", LastName = "Barker" }); people.Add(new Person() { FirstName = "Deane", LastName = "Annie" }); c.SetValue("people", people); Liquid {{ people | json }} Output [{"FirstName":"Deane","LastName":"Barker"},{"FirstName":"Deane","LastName":"Annie"}] Important Note: when rendering objects, this filter respects member access (see Member Access). If you’re restricting access to members, this might return a bunch of empty values. time_zone MethodMiscFilters.ChangeTimeZone format_number MethodMiscFilters.FormatNumber format_string MethodMiscFilters.FormatString Allows for token replacement within a string. It wraps the String.Format method in C#. Liquid {{ "Vehicle: {0}, Wheels: {1}" | format_string:"bicycle", 2 }} {{ "Vehicle: {0}, Wheels: {1}" | format_string:"car", 4 }} Output Vehicle: bicycle, Wheels: 2 Vehicle: car, Wheels: 4 You can set the culture with an optional named parameter of culture. format_date MethodMiscFilters.FormatDate This is the C# equivalent of date (see above). This does use the standard C# date formatting codes. Liquid {{ '2021-12-09' | format_date:'MMMM d, yyyy' }} Output December 9, 2021 md5 MethodMiscFilters.MD5 Generates a 32-digit MD5 hash of the input string. Liquid {{ "Deane" | md5 }} Output 8558b56b933bc4d7ba586407732a31e7 sha1 MethodMiscFilters.Sha1 Generates a 40-digit SHA-1 hash of the input string. Output 86284cbdb4649e52ff1ef657f257e2043e7f73af Liquid {{ "Deane" | sha1 }} sha256 MethodMiscFilters.Sha256 Generates a 64-digit SHA-256 hash of the input string. Liquid {{ "Deane" | sha256 }} Output c784dcfcc1e5231ff7d9ad4de123ee91bec736d806576a825315164c6431e01b