public function render($file, $data = null, $expires = false, $cache_mode = self::CACHE_USE_DEFAULT)
{
// Different $expires if user is anonymous or logged in
if (is_array($expires)) {
/** @var array $expires */
if (is_user_logged_in() && isset($expires[1])) {
$expires = $expires[1];
} else {
$expires = $expires[0];
}
}
$key = null;
$output = false;
if (false !== $expires) {
ksort($data);
$key = md5($file . json_encode($data));
$output = $this->get_cache($key, self::CACHEGROUP, $cache_mode);
}
if (false === $output || null === $output) {
$twig = $this->get_twig();
if (strlen($file)) {
$loader = $this->get_loader();
$result = $loader->getCacheKey($file);
do_action('timber_loader_render_file', $result);
}
$data = apply_filters('timber_loader_render_data', $data);
$data = apply_filters('timber/loader/render_data', $data, $file);
$output = $twig->render($file, $data);
}
if (false !== $output && false !== $expires && null !== $key) {
$this->delete_cache();
$this->set_cache($key, $output, self::CACHEGROUP, $expires, $cache_mode);
}
$output = apply_filters('timber_output', $output);
return apply_filters('timber/output', $output, $data, $file);
}