2

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();

reference

2 Answers 2

3

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.

2

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.

http://php.net/manual/en/regexp.reference.escape.php

5
  • Hm, not a Joomla guru, but can not find exactly this. In document.php : public $_tab = "\11"; from php docs - \11 - might be a back reference, or another way of writing a tab
    – Plamen
    Commented Oct 8, 2014 at 5:17
  • see my edit for further clarification Commented Oct 8, 2014 at 17:55
  • Thank you, but this do not answer my question, and it was way _getTab() returns two spaces (#20, #20), instead of one tab char (#09)? As far I understand from escape sequence \11 stands for octal 11 which is hex 09 (tab char). Somewhere, later this single tab is substituted with two spaces. Is it possible to be a template issue as well.
    – Plamen
    Commented Oct 8, 2014 at 19:12
  • Search your code base for "setTab(". The tab character can be changed, and somewhere in your install it is being changed to two spaces. Commented Oct 8, 2014 at 20:26
  • I made fresh new install of latest Joomla (3.3.6) with default settings. Nothing additional. There is no additional 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.
    – Plamen
    Commented Oct 11, 2014 at 4:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.