Пример #1
0
 /**
  * Fetch the parsed content from this template.
  *
  * @param string $template 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);
 }
Пример #2
0
 /**
  * The constructor will store the instance in the reference, preset some settings and map the custom modifiers.
  */
 public function __construct()
 {
     parent::__construct(func_get_arg(0), func_get_arg(1), func_get_arg(2));
     $this->debugMode = Model::getContainer()->getParameter('kernel.debug');
     $this->forkSettings = Model::get('fork.settings');
     // fork has been installed
     if ($this->forkSettings) {
         $this->themePath = FRONTEND_PATH . '/Themes/' . $this->forkSettings->get('Core', 'theme', 'default');
         $loader = $this->environment->getLoader();
         $loader = new \Twig_Loader_Chain(array($loader, new \Twig_Loader_Filesystem($this->getLoadingFolders())));
         $this->environment->setLoader($loader);
         // connect symphony forms
         $formEngine = new TwigRendererEngine($this->getFormTemplates('FormLayout.html.twig'));
         $formEngine->setEnvironment($this->environment);
         $this->environment->addExtension(new SymfonyFormExtension(new TwigRenderer($formEngine, Model::get('security.csrf.token_manager'))));
     }
     $this->environment->disableStrictVariables();
     // init Form extension
     new FormExtension($this->environment);
     // start the filters / globals
     TwigFilters::getFilters($this->environment, 'Frontend');
     $this->startGlobals($this->environment);
 }