code: public function onTwigRegistered(&$twig)
      {
          // If a theme is not found, it will be searched for in PicoAuth/theme
          $twig->getLoader()->addPath($this->pluginDir . '/theme');
  
          $this_instance = $this;
          $twig->addFunction(
              new \Twig_SimpleFunction(
                  'csrf_token',
                  function ($action = null) use (&$this_instance) {
                      return $this_instance->csrf->getToken($action);
                  },
                  array('is_safe' => array('html'))
              )
          );
          $twig->addFunction(
              new \Twig_SimpleFunction(
                  'csrf_field',
                  function ($action = null) use (&$this_instance) {
                      return '<input type="hidden" name="csrf_token" value="'
                          . $this_instance->csrf->getToken($action)
                          . '">';
                  },
                  array('is_safe' => array('html'))
              )
          );
      }
docs: Pico API event - onTwigRegistered
  
  Registers CSRF functions in Pico's Twig environment.
  
  @param \Twig_Environment $twig Reference to the twig environment