Skip to content

Functions

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

ceo

Provides whitelisted access to injected services.

Arguments

  • string service container name

Available service containers:

  • request
  • clientCode
  • config
  • security
  • cookies
  • gryphonConfig
  • registryService
  • timer
  • minifierService

Example

{% if ceo('request').getSegments(1) == 'some-slug' %}
    ...
{% endif %}
{% set styles %}
<style>
p {
    font-size: 14px;
}
</style>
{% endset %}
{% do ceo('minifierService').addCss(styles) %}
{# styles will be automatically hoisted to the top of the template #}

csrfToken

Provides CSRF token for form submissions

Arguments

  • None

Example

<form ...>
{{ csrfToken() }}
</form>

decrypt

Decrypt cypher text from CEO. Relies on the existing PSK.

Arguments

  • string cypher text

Example

{{ decrypt(entity.mySecureTextValue) }}

delayRender

DelayRender allows you to force rendered Twig code to the footer of the site. Helpful for javascript.

Arguments

  • string Twig string variable

Example

{% set javascript %}
<script>console.log('hello world');</script>
{% endset %}
{% do delayRender(javascript) %}

embedManager

Allows the view to directly disable embed middleware. Note this disables the embed middleware for the ENTIRE view, not just the partial or included template, but the entire output.

Arguments

  • None

fetch

Fetch allows for unhydrated data to be pulled into the template. Uses a fluent interface with ANSIISQL-like statements. Make sure to bind your variables to placeholders

Arguments

  • string model to work on

Fluid Methods

  • wherePublished()
  • orderBy(value[, direction])
  • limit(int)
  • where(string[, binds])
  • notWhere(string[, binds])
  • inWhere(string, array)
  • notInWhere(string, array)
  • first()
  • find()
  • findByASSOCATION(mixed)
    • find items by associated value, tags or authors for example

Example

{%
  set articles = fetch('article')
      .wherePublished()
      .find()
%}

{%
  set articles = fetch('article')
      .wherePublished()
      .where('slug = :slg:', {'slg': 'my-slug-yo'})
      .find()
%}

// You can also provide full class names to custom interfaces
{% set bloober = fetch('\\My\\Ns\\Bloober').orderForks().find() %}

merge

Merge two or more result sets. NOTE that this only works on CEO result sets and will not function on compatibility models.

Arguments

  • iterable
  • iterable*

Example

{%
    set hp = fetch('article')
                .wherePublished()
                .limit(10)
                .findByTags(['homepage'])
%}
{%
    set sports = fetch('article')
                .wherePublished()
                .limit(10)
                .findByTags(['sports'])
%}
{% set items = merge([hp, sports], 'published_at') %}
{% for item in items %}
    {{ macros.rssItem(item) }}
{% endfor %}

packStyles

Pack a hash of CSS styles into a single attribute. Use with unpackStyles to manipulate CSS styles.

Arguments

  • iterable

Example

{% set myStyles = unpackStyles(styleString) %}
{% set myStyles = myStyles|merge({
 'width': '100%',
 'margin': 'auto'
}) %}
<div style="{{ packStyles(myStyles) }}"></div>

cacheManager

Allows the view to directly disable static view cache. Note this disables the static cache for the ENTIRE view, not just the partial or included template, but the entire output.

Arguments

  • iterable

Example

{{ cacheManager({'disable': true}) }}

unpackStyles

Unpack a CSS style string into a hash. Use with packStyles to manipulate CSS styles.

Arguments

  • string

Example

{% set myStyles = unpackStyles(styleString) %}
{% set myStyles = myStyles|merge({
  'width': '100%',
  'margin': 'auto'
}) %}
<div style="{{ packStyles(myStyles) }}"></div>