How to Setup Title for Front-End Views

In the view file (view.html.php), the browser title is set in the protected function _prepareDocument() as:

$this->document->setTitle($title);

When the menu item is set, the browser title can be set from:

  1. Browser Page Title (in Page Display Options of Menu)
  2. Menu Title, if browser page title is blank
  3. Item Title ($this->item->title)
  4. Add site name if configured in global configuration
$app = JFactory::getApplication();
$menus = $app->getMenu();

$menu = $menus->getActive();

if ($menu)
{
$this->params->def('page_heading', $this->params->get('page_title', $menu->title));
}
else
{
$this->params->def('page_heading', JText::_('JGLOBAL_ARTICLES'));
}

If the menu is set, then define page_heading as page_title or in case page_title is empty, then define page_heading as the title of the menu.

$title = $this->params->get('page_title', '');

if (empty($title))
{
$title = $app->get('sitename');
}
elseif ($app->get('sitename_pagetitles', 0) == 1)
{
$title = JText::sprintf('JPAGETITLE', $app->get('sitename'), $title);
}
elseif ($app->get('sitename_pagetitles', 0) == 2)
{
$title = JText::sprintf('JPAGETITLE', $title, $app->get('sitename'));
}

if (empty($title))
{
$title = $this->item->title;
}

$this->document->setTitle($title);

Page Heading

To display page heading in the layout file:

<?php if ($this->params->get('show_page_heading')) : ?>
<div class="page-header">
<h1> <?php echo $this->escape($this->params->get('page_heading')); ?> </h1>
</div>
<?php endif; ?>