Skip to content
This repository has been archived by the owner on Feb 24, 2023. It is now read-only.

Latest commit

 

History

History
86 lines (70 loc) · 2.38 KB

options.md

File metadata and controls

86 lines (70 loc) · 2.38 KB

Options documentation

Customizing the Twig environment

// Define a directory as a Twig namespace, that can be used as:
//   {% include '@mynamespace/something.twig' %}
'amteich.twig.namespaces' => [
  'mynamespace' => 'mydirectory',
],

// Define a directory as a Twig namespace using a path given by Kirby.
// Must be called in Kirby's 'ready' option to have access to the Kirby object.
// Can be used as:
//   {% include '@mynamespace/something.twig' %}
'ready' => function () {
  return [
    'amteich.twig.namespaces' => [
      'mynamespace' => kirby()->root()->index() . '/mydirectory',
    ]
  ];
},

// Load an extension
'amteich.twig.env.extensions.intl' => 'Twig\\Extra\\Intl\\IntlExtension',

// Expose an existing function in templates
'amteich.twig.env.functions' => [
  'myfunction' => 'myCustomFunction'
],

// Expose an existing function in templates as a filter
'amteich.twig.env.filters' => [
  'myfilter' => 'myCustomFilter'
],

// Expose a twig test function for templates
'amteich.twig.env.tests' => [
  'of_type' => function ($var, $typeTest) {
      switch ($typeTest)
      {
        default:
          return false;
          break;

        case 'array':
          return is_array($var);
          break;

        case 'bool':
          return is_bool($var);
          break;

        case 'string':
          return is_string($var);
          break;
      }
  },
],

See Using your own functions in templates for details about Twig functions and filters.

Advanced

// Should we use .php templates as fallback when .twig
// templates don't exist? Set to false to only allow Twig templates
'amteich.twig.usephp' => true

// Use Twig’s PHP cache?
// Enabling Twig's cache can give a speed boost to pages with changing
// content (e.g. a search result page), because Twig will use a compiled
// version of the template when building the response.
// But if you have static text content in your Twig templates, you won’t
// see content changes until you manually remove the `site/cache/twig` folder.
'amteich.twig.cache' => false

// Disable autoescaping or specify autoescaping type
// http://twig.sensiolabs.org/doc/api.html#environment-options
'amteich.twig.autoescape' => false | 'html'

// Should Twig throw errors when using undefined variables or methods?
// Defaults to the value of the 'debug' option
'amteich.twig.strict' => option('debug', false)