public getContent ( string $template ) : string | ||
$template | string | The location of the template file, used to display this template. |
return | string | The actual parsed content after executing this template. |
public function getContent($template)
{
$this->parseConstants();
$this->parseAuthentication();
$this->parseAuthenticatedUser();
$this->parseDebug();
$this->parseLabels();
$this->parseLocale();
$this->parseVars();
$template = str_replace(BACKEND_MODULES_PATH, '', $template);
// path to TwigBridge library so we can locate the form theme files.
$appVariableReflection = new ReflectionClass(AppVariable::class);
$vendorTwigBridgeDir = dirname($appVariableReflection->getFileName());
// render the compiled File
$loader = new Twig_Loader_Filesystem(array(BACKEND_MODULES_PATH, BACKEND_CORE_PATH, $vendorTwigBridgeDir . '/Resources/views/Form'));
$twig = new Twig_Environment($loader, array('cache' => Model::getContainer()->getParameter('kernel.cache_dir') . '/twig', 'debug' => $this->debugMode));
// connect symphony forms
$formEngine = new TwigRendererEngine(array('Layout/Templates/FormLayout.html.twig'));
$formEngine->setEnvironment($twig);
$twig->addExtension(new SymfonyFormExtension(new TwigRenderer($formEngine, Model::get('security.csrf.token_manager'))));
$twigTranslationExtensionClass = Model::getContainer()->getParameter('twig.extension.trans.class');
$twig->addExtension(new $twigTranslationExtensionClass(Model::get('translator')));
// debug options
if ($this->debugMode === true) {
$twig->addExtension(new Twig_Extension_Debug());
}
if (count($this->forms) > 0) {
foreach ($this->forms as $form) {
$twig->addGlobal('form_' . $form->getName(), $form);
}
}
// should always be included, makes it possible to parse SpoonForm in twig
new FormExtension($twig);
// start the filters / globals
TwigFilters::getFilters($twig, 'Backend');
$this->startGlobals($twig);
return $twig->render($template, $this->variables);
}
/** * Display, this wil output the template to the browser * If no template is specified we build the path form the current module and action * * @param string $template The template to use, if not provided it will be based on the action. */ public function display($template = null) { // parse header $this->header->parse(); /* * If no template is specified, we have to build the path ourself. The default template is * based on the name of the current action */ if ($template === null) { $template = '/' . $this->getModule() . '/Layout/Templates/' . $this->URL->getAction() . '.html.twig'; } $this->content = $this->tpl->getContent($template); }