-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathPhpTwigExtension.php
44 lines (38 loc) · 1.1 KB
/
PhpTwigExtension.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
<?php
namespace Grav\Plugin;
use Grav\Common\Grav;
use Grav\Common\Page\Page;
use Grav\Common\Cache as Cache;
use Grav\Common\GPM\Response;
use Grav\Plugin\Utils;
require_once(__DIR__ . "/Utils.php");
class PhpTwigExtension extends \Grav\Common\Twig\TwigExtension
{
public function getName()
{
return 'PhpTwigExtension';
}
public function getFunctions() : array
{
return [
new \Twig_SimpleFunction('phpTest', [$this, 'Test']),
new \Twig_SimpleFunction('collectionToEventsByDate', [$this, 'collectionToEventsByDate']),
];
}
static function Test() {
echo date("Y-m-d", strtotime(str_replace(' ','', "7. 9. 2020")));
}
public static function collectionToEventsByDate($collection){
$array = array();
foreach($collection as $event) {
$date = $event->value("header.start");
$today = date('Y-m-d');
if ($date < $today) {
$date = $today;
}
$array[$date][] = $event;
}
return $array;
}
}
?>