Project

General

Profile

Actions

Bug #75455

closed

TypoScript includeJs does not respect parameter

Added by Stefan Weißwange over 8 years ago. Updated over 8 years ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
TypoScript
Target version:
Start date:
2016-04-08
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
8
PHP Version:
Tags:
Complexity:
Is Regression:
No
Sprint Focus:

Description

page.includeJS does not respect parameter(s) for the included javascript. Some examples to reproduce the problem, assuming the JavaScript-files exists remote and local.

This works:

page.includeJS.myscript = http://SOMEDOMAIN/JS/myscript.js?parameter=value
page.includeJS.myscript.external = 1

This works:

page.includeJS.myscript = http://SOMEDOMAIN/JS/myscript.js
page.includeJS.myscript.external = 1

This works:

page.includeJS.myscript = fileadmin/JS/myscript.js

This does not work:

page.includeJS.myscript = fileadmin/JS/myscript.js?parameter=value

Actions #1

Updated by Stephan Großberndt over 8 years ago

  • Status changed from New to In Progress
  • TYPO3 Version changed from 6.2 to 8
  • PHP Version deleted (5.4)

This happens on master, 8, 7.6 and 6.2. It depends on the location of the file


# Will not include the file
page.includeJS.scriptaculous = /fileadmin/javascript.js?parameter=value

# Will not include the file
page.includeJS.scriptaculous = 1:/javascript.js?parameter=value

# Will include the file on master, 8, 7.6 but not on 6.2
page.includeJS.scriptaculous = EXT:extension/Resources/Public/JavaScript/javascript.js?parameter=value

This is due to \TYPO3\CMS\Frontend\Page\PageGenerator::renderContentWithHeader:

$ss = $tsfe->pSetup['includeJSFooter.'][$key . '.']['external'] ? $JSfile : $tsfe->tmpl->getFileName($JSfile);

which calls \TYPO3\CMS\Core\TypoScript\TemplateService::getFileName if external=1 is not set.

Actions #2

Updated by Stephan Großberndt over 8 years ago

The difference for EXT: between 6.2 and newer versions is due to the check for EXT:@in TemplateService in 6.2 versus using @GeneralUtility::getFileAbsFileName() in 7.6 and newer. TemplateService->getFileName actually checks for file existence with file_exists while GeneralUtility::getFileAbsFileName() "only" checks using GeneralUtility::validPathStr().

I discussed this with Wouter, since we want to educate people to use extensions to provide JavaScript files and not put them in fileadmin, the current behaviour for master, 8 and 7.6 is ok.

The remaining question is whether to change the behaviour in 6.2 or not: Use the check from GeneralUtility::getFileAbsFileName() instead of the current code:

        if (substr($file, 0, 4) === 'EXT:') {
            $newFile = '';
            list($extKey, $script) = explode('/', substr($file, 4), 2);
            if ($extKey && \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded($extKey)) {
                $extPath = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath($extKey);
                $newFile = \TYPO3\CMS\Core\Utility\PathUtility::stripPathSitePrefix($extPath) . $script;
            }
            if (!@file_exists((PATH_site . $newFile))) {
                if ($this->tt_track) {
                    $GLOBALS['TT']->setTSlogMessage('Extension media file "' . $newFile . '" was not found!', 3);
                }
                return;
            } else {
                $file = $newFile;
            }
        }
Actions #3

Updated by Stephan Großberndt over 8 years ago

I also updated the documentation not to feature examples including files from fileadmin anymore:

https://github.com/TYPO3-Documentation/TYPO3CMS-Reference-Typoscript/pull/60

Actions #4

Updated by Stephan Großberndt over 8 years ago

  • Status changed from In Progress to Closed

As discussed in #typo3-cms-coredev this will not be fixed for TYPO3 6.2 since this is no critical / security / browser-related issue.

In all current versions of TYPO3 you can use the external = 1 flag to include the files:

page.includeJS.myscript = fileadmin/myscript.js?p=m
page.includeJS.myscript.external = 1

In master, 8 and 7.6 you do not need to flag the file as external if you put it in EXT:

page.includeJS.myscript = EXT:myextension/Rescources/Public/JavaScript/myscript.js?p=m
Actions #5

Updated by Stefan Weißwange over 8 years ago

Just to be sure: This ist not a problem with including external or internal files in general!

At this point, TypoScript (at least in 6.2 LTS) is not working as expected, since a parameter for a JS-file can only be used if the JS-file is external.

This works:
page.includeJS.myscript = http://SOMEDOMAIN/JS/myscript.js?parameter=value
page.includeJS.myscript.external = 1

This does not work:
page.includeJS.myscript = fileadmin/JS/myscript.js?parameter=value

Actions

Also available in: Atom PDF