/**
* 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;
}