taxonomylist.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace Grav\Plugin;
  3. use Grav\Common\Plugin;
  4. use Grav\Plugin\Taxonomylist;
  5. class TaxonomylistPlugin extends Plugin
  6. {
  7. /**
  8. * @return array
  9. */
  10. public static function getSubscribedEvents()
  11. {
  12. return [
  13. 'onPluginsInitialized' => ['onPluginsInitialized', 0]
  14. ];
  15. }
  16. /**
  17. * Initialize configuration
  18. */
  19. public function onPluginsInitialized()
  20. {
  21. if ($this->isAdmin()) {
  22. $this->active = false;
  23. return;
  24. }
  25. $this->enable([
  26. 'onTwigTemplatePaths' => ['onTwigTemplatePaths', 0],
  27. 'onTwigSiteVariables' => ['onTwigSiteVariables', 0]
  28. ]);
  29. }
  30. /**
  31. * Add current directory to twig lookup paths.
  32. */
  33. public function onTwigTemplatePaths()
  34. {
  35. $this->grav['twig']->twig_paths[] = __DIR__ . '/templates';
  36. }
  37. /**
  38. * Set needed variables to display the taxonomy list.
  39. */
  40. public function onTwigSiteVariables()
  41. {
  42. require_once __DIR__ . '/classes/taxonomylist.php';
  43. $twig = $this->grav['twig'];
  44. $twig->twig_vars['taxonomylist'] = new Taxonomylist();
  45. $twig->twig_vars['list_url'] = $this->config->get(
  46. 'site.blog.route',
  47. $this->config->get('plugins.taxonomylist.route')
  48. );
  49. }
  50. }