Why does the following code return two spaces instead of one tab? How can I change this setting easily?
$document = JFactory::getDocument();
$tab = $document->_getTab();
Why does the following code return two spaces instead of one tab? How can I change this setting easily?
$document = JFactory::getDocument();
$tab = $document->_getTab();
Two spaces are hard coded in protected static function createDocument()
located inside libraries/joomla/factory.php
:
$attributes = array(
'charset' => 'utf-8',
'lineend' => 'unix',
'tab' => ' ',
'language' => $lang->getTag(),
'direction' => $lang->isRTL() ? 'rtl' : 'ltr',
'mediaversion' => $version->getMediaVersion()
);
which overrides previous class property declaration of \11
in libraries/joomla/document/document.php
and all rows in the head section become indented with 2 spaces.
If you read the method documentation, it is doing exactly what its supposed to. Which is return the system default for the number of spaces a keyboard tab event contains.
Below is the method as taken from JDocument class:
/**
* Returns a string containing the unit for indenting HTML
*
* @return string
*
* @since 11.1
*/
public function _getTab()
{
return $this->_tab;
}
And the class property for $_tab:
/**
* Tab string
*
* @var string
* @since 11.1
*/
public $_tab = "\11";
Using the above and referencing the PHP Documents for Escape Sequences in text we see a reference to exact string:
\11
might be a back reference, or another way of writing a tab
You can visit the below link for more info, but the method in question returns the PHP escape sequence for a tab.
public $_tab = "\11";
from php docs - \11 - might be a back reference, or another way of writing a tab
setTab
except the one in document.php. The result is same - if you look at page source you will notice two spaces in front of the tags in the head section. I think that there should be two tabs.