Example #1
0
 /**
  * Render a help template (or return false if none found).
  *
  * @param string $name    Template name to render
  * @param array  $context Variables needed for rendering template; these will
  * be temporarily added to the global view context, then reverted after the
  * template is rendered (default = empty).
  *
  * @return string|bool
  */
 public function render($name, $context = null)
 {
     // Set up the needed context in the view:
     $this->contextHelper->__invoke($this->getView());
     $oldContext = $this->contextHelper->apply(null === $context ? [] : $context);
     // Sanitize the template name to include only alphanumeric characters
     // or underscores.
     $safe_topic = preg_replace('/[^\\w]/', '', $name);
     // Clear warnings
     $this->warnings = [];
     try {
         $tpl = "HelpTranslations/{$this->language}/{$safe_topic}.phtml";
         $html = $this->getView()->render($tpl);
     } catch (RuntimeException $e) {
         try {
             // language missing -- try default language
             $tplFallback = 'HelpTranslations/' . $this->defaultLanguage . '/' . $safe_topic . '.phtml';
             $html = $this->getView()->render($tplFallback);
             $this->warnings[] = 'Sorry, but the help you requested is ' . 'unavailable in your language.';
         } catch (RuntimeException $e) {
             // no translation available at all!
             $html = false;
         }
     }
     $this->contextHelper->restore($oldContext);
     return $html;
 }
Example #2
0
 /**
  * Render the contents of the specified record tab.
  *
  * @param \VuFind\RecordTab\TabInterface $tab Tab to display
  *
  * @return string
  */
 public function getTab(\VuFind\RecordTab\TabInterface $tab)
 {
     $context = ['driver' => $this->driver, 'tab' => $tab];
     $classParts = explode('\\', get_class($tab));
     $template = 'RecordTab/' . strtolower(array_pop($classParts)) . '.phtml';
     $oldContext = $this->contextHelper->apply($context);
     $html = $this->view->render($template);
     $this->contextHelper->restore($oldContext);
     return $html;
 }