-
Notifications
You must be signed in to change notification settings - Fork 4
/
functions.php
52 lines (44 loc) · 1.3 KB
/
functions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
/*
* Commented Include Twig Extension Component
*
* Copyright (C) Boris Đemrovski <djboris88@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Djboris88\Timber;
use Djboris88\Twig\Extension\CommentedIncludeExtension;
/**
* @param $twig \Twig_Environment;
*
* @return \Twig_Environment
*/
function add_commented_include_extension($twig)
{
$twig->addExtension(new CommentedIncludeExtension());
return $twig;
}
/**
* Tries to initialize the twig extension, if it has not been already.
*/
function initialize_filters()
{
if (
!defined('WP_DJBORIS88_TIMBER_FILTERS_INITIALIZED')
&& defined('WP_DEBUG')
&& WP_DEBUG
&& function_exists('add_filter')
) {
define('WP_DJBORIS88_TIMBER_FILTERS_INITIALIZED', TRUE);
add_filter('timber/loader/twig', sprintf('%s\\add_commented_include_extension', __NAMESPACE__));
/**
* Adding a second filter to cover the `Timber::render()` case, when the
* template is not loaded through the `include` tag inside a twig file
*/
add_filter( 'timber/output', function( $output, $data, $file ) {
return "\n<!-- Begin output of '" . $file . "' -->\n" . $output . "\n<!-- / End output of '" . $file . "' -->\n";
}, 10, 3 );
}
}
initialize_filters();