Back to HtmlView class

Method display

public void
display
(mixed $tpl = null)
Execute and display a template script.
Parameters
  • string $tpl The name of the template file to parse; automatically searches through the template paths.
Returns
  • void
Since
  • 3.0
-
  • \Exception
  • \JViewLegacy::loadTemplate()
Class: HtmlView
Project: Joomla

Method display - Source code

/**
 * Execute and display a template script.
 *
 * @param   string  $tpl  The name of the template file to parse; automatically searches through the template paths.
 *
 * @return  void
 *
 * @throws  \Exception
 * @see     \JViewLegacy::loadTemplate()
 * @since   3.0
 */
public function display($tpl = null)
{
    $app = Factory::getApplication();
    if ($this->option) {
        $component = $this->option;
    } else {
        $component = ApplicationHelper::getComponentName();
    }
    $context = $component . '.' . $this->getName();
    $app->getDispatcher()->dispatch('onBeforeDisplay', AbstractEvent::create('onBeforeDisplay', ['eventClass' => 'Joomla\\CMS\\Event\\View\\DisplayEvent', 'subject' => $this, 'extension' => $context]));
    $result = $this->loadTemplate($tpl);
    $eventResult = $app->getDispatcher()->dispatch('onAfterDisplay', AbstractEvent::create('onAfterDisplay', ['eventClass' => 'Joomla\\CMS\\Event\\View\\DisplayEvent', 'subject' => $this, 'extension' => $context, 'source' => $result]));
    $eventResult->getArgument('used', false);
    echo $result;
}