From 0cb04bfe6f8c5d0841a274331bbdb6b9f125f047 Mon Sep 17 00:00:00 2001 From: Robert Down Date: Mon, 15 May 2017 00:34:48 -0400 Subject: [PATCH] Add global twig environment and loader (#745) Adds a twig environment and twig filesystem loader to the globals array ```php $GLOBALS['twigLoader']->addPath('path/to/your/templates'); $displayVariables = [ 'array of variables' => 'to pass to template', ]; echo $GLOBALS['twig']->render('template-name.html.twig'); ``` --- interface/globals.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/interface/globals.php b/interface/globals.php index d0e672298..b747e553c 100644 --- a/interface/globals.php +++ b/interface/globals.php @@ -193,6 +193,31 @@ define("_MPDF_TTFONTDATAPATH", $GLOBALS['OE_SITE_DIR'] . '/documents/mpdf/ttfont // library/translation.inc.php - Includes translation functions require_once $GLOBALS['vendor_dir'] ."/autoload.php"; +// @TODO This needs to be broken out to it's own function, but for time's sake +// @TODO putting it here until we land on a good place. RD 2017-05-02 + +$twigOptions = [ + 'debug' => false, +]; + +$twigLoader = new Twig_Loader_Filesystem(); +$twigEnv = new Twig_Environment($twigLoader, $twigOptions); + +if (array_key_exists('debug', $twigOptions) && $twigOptions['debug'] == true) { + $twigEnv->addExtension(new Twig_Extension_Debug()); +} +$twigEnv->addGlobal('assets_dir', $GLOBALS['assets_static_relative']); +$twigEnv->addGlobal('srcdir', $GLOBALS['srcdir']); +$twigEnv->addGlobal('rootdir', $GLOBALS['rootdir']); +$twigEnv->addFilter(new Twig_SimpleFilter('translate', function ($string) { + return xl($string); +})); + +/** Twig_Loader */ +$GLOBALS['twigLoader'] = $twigLoader; +/** Twig_Environment */ +$GLOBALS['twig'] = $twigEnv; + // This will open the openemr mysql connection. require_once (dirname(__FILE__) . "/../library/sql.inc"); -- 2.11.4.GIT