This repository has been archived by the owner on Jun 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
blogroll.php
54 lines (48 loc) · 1.61 KB
/
blogroll.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
53
54
<?php
namespace Grav\Plugin;
use Grav\Common\Plugin;
use RocketTheme\Toolbox\Event\Event;
/**
* Class BlogrollPlugin
* @package Grav\Plugin
*/
class BlogrollPlugin extends Plugin
{
/**
* @return array
*
* The getSubscribedEvents() gives the core a list of events
* that the plugin wants to listen to. The key of each
* array section is the event that the plugin listens to
* and the value (in the form of an array) contains the
* callable (or function) as well as the priority. The
* higher the number the higher the priority.
*/
public static function getSubscribedEvents()
{
return [
'onTwigSiteVariables' => ['onTwigSiteVariables', 0],
'onTwigTemplatePaths' => ['onTwigTemplatePaths', 0]
];
}
public function onTwigTemplatePaths()
{
//Load the built-in twig unless overridden
$this->grav['twig']->twig_paths[] = __DIR__ . '/templates';
}
public function onTwigSiteVariables()
{
//Load the custom PHP for generating the lists
require_once __DIR__ . '/classes/blogroll.php';
//Pass a reference to the custom object to the templates
$this->grav['twig']->twig_vars['blogroll'] = new Blogroll();
//Load the correct CSS based on the `built_in_css` field
if ($this->config->get('plugins.blogroll.built_in_css')) {
$this->grav['assets']
->add('plugin://blogroll/assets/blogroll.css');
} else {
$this->grav['assets']
-> add('theme://assets/blogroll.css');
}
}
}