[TYPO3-dev] Add own require.js module in extension

Philipp Wrann philippwrann at gmail.com
Mon Jul 13 14:14:55 CEST 2015


Hm, strange, that is exactly what i am doing but it does not work.

I wrote a viewhelper for such purposes (dont need the container because its used inside an userFunc TCA field, simply adding some buttons)

<t:pageRenderer></t:pageRenderer>

My Call:
<t:pageRenderer
	includeRequireJsModules="{
		0 :'VENDOR/PACKAGE/FormEngine'
	}"
/>

It takes an argument: includeRequireJsModules [array]

The ViewHelper is like:

class PageRendererViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper {
	
	/**
	 * @var \TYPO3\CMS\Core\Page\PageRenderer
	 * @inject
	 */
	protected $pageRenderer;
	
	/**
	 * @param array $addCssLibraries [optional]
	 * @param array $addCssFiles [optional]
	 * @param array $addJsLibraries [optional]
	 * @param array $addJsFiles [optional]
	 * @param array $includeRequireJsModules [optional]
	 * @param array $addJsFooterFiles [optional]
	 * @return void
	 */
	public function render(array $addCssLibraries = [], array $addCssFiles = [], array $addJsLibraries = [], array $addJsFiles = [], array 
		foreach ($includeRequireJsModules as $module) {
			$this->pageRenderer->loadRequireJsModule($module);
		}
	}
	
}

I the frontend the console logs
GET 
http://project.local/typo3/VENDOR/PACKAGE/FormEngine.js [HTTP/1.1 404 Not Found 0ms]
Error: Script error for: VENDOR/PACKAGE/FormEngine
http://requirejs.org/docs/errors.html#scripterror

I figured it could be neccessary to add the RequireJS Config, but it didnt.
If i add the config within ext_tables.php everything is messed up because the pagerenderer wont set the default namespaces if some config has been made.

If i add it on the fly in my viewhelper it has no effect.


In PageRenderer::loadRequireJs () this is processed:
if ($fullJsPath) {
					$this->requireJsConfig['paths']['TYPO3/CMS/' . GeneralUtility::underscoredToUpperCamelCase($packageName)] = $this->backPath . $fullJsPath;
				}

So - do i have to write something like this?
<t:pageRenderer
	includeRequireJsModules="{
		0 : 'TYPO3/CMS/package/FormEngine'
	}"
/>

Becuase that does not work either

Neither does: TYPO3/CMS/Vendor.Package/Module
Nor: TYPO3/CMS/Package/Module

Yes - my file is located at:
extkey/Resources/Public/JavaScript/FormEngine.js

Its content is like:
define('Vendor/Package/FormEngine',[],function($){

});

I have to say, i didnt work with require.js before - anyway i think the problem has to do with my integration - not the usage of require.js



More information about the TYPO3-dev mailing list