Skip to content

Filters

CEO provides a number of useful filters and functions beyond the standard set found in Twig.

asset

Asset replicates Gryphon's original Asset filter, providing asset urls depending on application location.

Arguments

  • None

Example

  {{ 'foo/bar'|asset }}

clip

Attempts to trim a string to length

Arguments

  • int character limit

Example

{{ article.abstract|clip(100) }}

coerce

Typeless languages are kind of a pain. This filter allows you to coerce a twig variable into a fixed primitive type.

Coercion filters:

  • string
  • int
  • float
  • bool

Example

{{ myVar|coerce('int') + 4321 }}

date

Date overrides the Twig 'date' filter. As all dates are stored and handled in UTC, this converts them to the local timezone before display. Literally just a backward compatible copy of localDate.

Arguments

  • string Date format (see table)

Example

{{ 'now'|date('m/d/y g:ia') }}

extract

Extract is a dropin replacement for Gryphon's extract filter, using the new paragraph extraction functionality. Under the hood, it leverages CEO's text extraction library.

Arguments

  • int number of paragraphs to extract, use null to extract all remaining
  • int number of paragraphs to skip

Example

{{ article.copy|extract(limit) }}
{{ article.copy|extract(limit, offset) }}

int2noun

Pluralizes or singularizes text based on the integer value.

Arguments

  • string

Example

{{ 1|int2noun('People') }} # 1 Person
{{ 5|int2noun('Cat') }} # 5 Cats

jsonDecode

Corollary to jsonEncode, can be used to re-hydrate data.

Arguments

  • None

localDate

As all dates are stored and handled in UTC, this converts them to the local timezone before display. Can accept integer timestamps, date strings and ANSI SQL timestamps.

Arguments

  • string date format

Example

{{ 'now'|localDate('m/d/y g:ia') }}

push

Push an item onto an iterable.

Arguments

  • mixed

Example

{% do myArray|push(myObject) %}

qualifiedUrl

Generate a fully qualified URL. Literally just a backward compatible copy of url.

Arguments

  • iterable hash of query parameters

stripTags

StripTags overrides Twig's striptags filter. The default filter isn't HTML safe, and while we're stripping tags, we're not stripping non-escaped characters, like  .

If you need fully parsable, clean, stripped text, use the |e filter.

Arguments

  • string mask list

Example

 {{ text|striptags }} # strip all tags
 {{ text|striptags('<p><br>') }} # strip all tags except <p> and <br>

timeSince

Returns a fuzzy time based on timestamp.

Arguments

  • None

Example

{{ article.published_at|timeSince }} # 4 hours ago

transform

Apply transformations to images processed through CEO. See the Imgix API for more information on valid parameters.

Arguments

  • iterable hash of query parameters

Example

{{ article.dominantMedia.url|transform({
  'w': 1000,
  'h': 1000,
  'ar': '1:1'
}) }}

url

Url replicates Gryphon's original URL filter, providing absolute urls regardless of leading slash.

Please note this behavior is different from the built in url() function which will not automatically inject a leading slash.

Arguments

  • iterable hash of query parameters
  • boolean true to expand to fully qualified url

Example

{{ 'foo/bar'|url({'a': 1}) }} becomes /foo/bar?a=1
{{ 'foo/bar'|url({'a': 1}, true) }} becomes https://mysite.com/foo/bar?a=1
{{ 'http://example.tld/bar'|url }} becomes http://example.tld/bar