Created
January 12, 2016 01:11
-
-
Save alexweissman/efa3d0ef5b273e987d79 to your computer and use it in GitHub Desktop.
Custom Grav theme to interact with UserFrosting
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Grav\Theme; | |
class CollegeParkTutors extends Antimatter { | |
public function onTwigTemplatePaths() { | |
$grav_twig = $this->grav['twig']; | |
$uf_dir = realpath(ROOT_DIR . '/..') . '/common/'; | |
$grav_twig->twig_paths[] = $uf_dir . "templates/collegeparktutors"; | |
} | |
public function onTwigSiteVariables() { | |
// Get Grav variables | |
$grav_twig = $this->grav['twig']; | |
$grav_site = $this->grav['config']['site']; | |
// Load UF | |
$uf_dir = realpath(ROOT_DIR . '/..') . '/common/'; | |
require_once( $uf_dir . "config/config-collegeparktutors.php" ); | |
require_once( $uf_dir . "initialize.php" ); | |
$app = \Slim\Slim::getInstance(); | |
// Replace Grav's global Twig variables with our own | |
unset($grav_twig->twig_vars['site']); | |
$grav_twig->twig_vars['site'] = $app->site; | |
$function_error_log = new \Twig_SimpleFunction('errorLog', function ($obj) { | |
error_log(print_r($obj, true)); | |
}); | |
$grav_twig->twig->addFunction($function_error_log); | |
// Add Twig functions for including CSS and JS scripts from schema | |
$function_include_css = new \Twig_SimpleFunction('includeCSS', function ($group_name = "common") { | |
// Return array of CSS includes | |
$app = \Slim\Slim::getInstance(); | |
return $app->schema->getCSSIncludes($group_name, $app->site['minify_css']); | |
}); | |
$grav_twig->twig->addFunction($function_include_css); | |
$function_include_bottom_js = new \Twig_SimpleFunction('includeJSBottom', function ($group_name = "common") { | |
// Return array of JS includes | |
$app = \Slim\Slim::getInstance(); | |
return $app->schema->getJSBottomIncludes($group_name, $app->site['minify_js']); | |
}); | |
$grav_twig->twig->addFunction($function_include_bottom_js); | |
$function_include_top_js = new \Twig_SimpleFunction('includeJSTop', function ($group_name = "common") { | |
// Return array of JS includes | |
$app = \Slim\Slim::getInstance(); | |
return $app->schema->getJSTopIncludes($group_name, $app->site['minify_js']); | |
}); | |
$grav_twig->twig->addFunction($function_include_top_js); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment