TYPO3 extension - f:uri.resource returns wrong path - typo3

I'm writing a backend module for my own TYPO3 extension, where I'm wrapping the content into a be.container including a CSS and a JS file:
<f:be.container
includeCssFiles="{0: '{f:uri.resource(path:\'CSS/backend.css\')}'}"
includeJsFiles="{0: '{f:uri.resource(path:\'JS/backend.js\')}'}"
>
<!-- module content -->
</f:be.container>
None of those resources gets included though. When I'm rendering f:uri.resource directly into the HTML, it - no matter which path - resolves to
/typo3/
which makes no sense to me. In my project, /typo3/ is the path where the TYPO3 core is symlinked to, relative to my web path.
I've assured that my resource files are placed in EXT:my_extension/Resources/Public/CSS/backend.css and EXT:my_extension/Resources/Public/JS/backend.js respectively. I had a similiar issue including resources in the frontend, where it would resolve to just a / - in the end I decided to go with inclusion via Typoscript instead. I'm not sure if I'll be able to do this for the backend module as well. Any idea how to solve this? Maybe I missed something in the configuration which messes up path resolution for f:uri.resource. Any help would be appreciated.

For a minimal test case, try putting the plain output into your fluid template:
{f:uri.resource(path:'CSS/backend.css')}
If that yields the same result, it seems like the ViewHelper is not aware of the current extension. You can pass it the extension key as argument, see https://docs.typo3.org/other/typo3/view-helper-reference/9.5/en-us/typo3/fluid/latest/Uri/Resource.html.

Related

DDEV accessing wrong .css-file, different home base the productive system

I'm working on a downloaded productive TYPO3 homepage (v11.5) and set it up in DDEV.
Now during my work I recognised that the base href for inclusion of user-specified .css-files are different from the productive system.
While in the productive system, the .css-file is correctly loaded from
https://mydomain.at/fileadmin/templates/assets/css/mybootstrap2.css?1636470015
it is in the DDEV environment requested from
https://mydomain.ddev.site/sternwarte-mydomain/fileadmin/templates/assets/css/mybootstrap2.css?1674722424
Which obviously added a Typo3 page references (sternwarte-mydomain/) to the path, an therefore correctly resulted in an
net::ERR_ABORTED 404
for the GET-operation as this is the wrong location.
Any hints/suggestions where my error could be.
EDIT:
Extract of the Typoscript.
Resulting sourcecode
EDIT 2:
Site configuration:
Maybe you need to set config.absRefPrefix = / in TypoScript? Or check the entry point of your site configuration.
Update:
Try to set the link to the CSS file with a slash in front, e.g. file1 = /fileadmin/templates/assets/css/mybootstrap2.css. Or try to set config.baseURL = /.

Umbraco with Windsor Castle error after adding nuPickers plugin

With an existing Umbraco site running fine we added the nuPickers plugin which does not seem to like Castle. In the browser console we are seeing a lot of 404 / 500 errors being generated for the embedded resources within the plugin. (The plugin is a single DLL with css and js files embedded in it.)
The site continues running fine (back and front ends), except for the plugin.
The Event log is showing: "No component for supporting the service nuPickers.EmbeddedResourceController was found"
We have tried route.ignoreroute in our route config, and also adding a handler in web.config, both unsuccessfully, as we do not think the resource requests should be getting to castle?
Any help or pointers gratefully accepted!
Just in case anyone comes across this ticket, we 'solved' this by
Getting all of the embedded resources, (html, js & css - not the classes)
Physically placing them inside the App_plugins folder in the correct structure (as they were being requested),
Renaming the js and css files (by adding the .nu after the file
extension), and,
Adding the following mime types into the web.config
mimeMap fileExtension=".css.nu" mimeType="text/css"
mimeMap fileExtension=".js.nu" mimeType="application/javascript"
Then, everything seems to work - but there MUST be a better solution, surely?

TypoScript: Check if JS/CSS File is already included

anybody knows how to check if a js/css file is already included with typoscript?
Example
[Template_A.ts]
page.includeJS {
jsfile = fileadmin/Template/js/jquery-1.10.2.min.js
}
now if i got an extension with the same include e.g.
[Extension_A.ts]
page.includeJS {
jsfile = fileadmin/Template/js/jquery-1.10.2.min.js
}
Is there a way to prevent this kind of double code injection? Maybe i got another Template e.g. Template_B.ts where jquery is not included - than the Extension_A.ts has to include jquery by itself.
Kinldy
You can use the same key inside includeJS such it just gets overridden if you include the file twice.
Other than that you should put jQuery into includeJSlibs, such that it is loaded before the other JS files.
Other than that, the TS should be unique for each page. Therefore you always to make sure anyway that all resources are included in-order.
You should not include JS libs with the automatic extension TS setups. Use your documentation to tell the integrator what needs to be included and what not.
The various and independent inclusion of scripts by plugins and templates is one of the tricky points in TYPO3. As far as I know, this point cannot be managed at one single point.
There is a plugin "t3jquery" that offers to build, compress and share a common jQuery library. It also has a service to analyze other plugins for their dependencies. But this doesn't solve the problem in general, as many plugins don't check for libraries already loaded.
The most stable way is to remove all plugin's references to libraries manually in your TypoSkript. This gives you some simple additional TypoSkript lines. I use lines like these:
plugin.tx_imagecycle_pi1.file.jQueryLibrary >
plugin.tx_imagecycle_pi1.jQueryLibrary >
plugin.tx_multicontent_pi1.file.jQueryLibrary >
plugin.tx_multicontent_pi1.jQueryLibrary >
# Fluid
page.headerData.998 >
You can find the matching TypoSkript descriptors by searching for the library name in the TypoSkript browser or by greping in the plugin's source code. You will also need this if you wish to add libraries as part of content that was get by AJAX, thus separating the libs from the page content.
Here's a tut (in German): http://jweiland.net/typo3/typoscript/javascript-manuell-entfernen-oder-einbinden.html
Futher possibilities you can check:
Some plugins are written in good structure and offer to keep back their Javascript in the settings.
Some script inclusions may come rather from the static template but from a plugin, so don't forget to have a look there.

Loading Require.js plugins

How do you load a require.js plugin?!
I've read all the docs - http://requirejs.org/docs/plugins.html - but unless I've missed it, nowhere does it tell you how to load a plugin. I'm trying to load the "text" one. If I require something like: template: 'text!template.html' Chrome just gives /text!template.html.js 404 (Object Not Found), so presumably the text plugin isn't loading.
I've put it in the same dir as require.js, and tried adding it in my require header, but it doesn't seem to find it.
What have I missed?! I'm using the combined jquery-require.js file, if that is relevant. i.e. http://requirejs.org/docs/download.html#samplejquery
I worked this out. Nothing to do with require.js, schoolboy error with the webserver permissions meant the file wasn't being served. For reference, in the require.config just put text :"PATH_TO_FILE" and it will find it when you reference "text!:...".

How to make Modules use Application View Helpers?

Since, adding some extra modules to the zend framework application, a lot of errors are popping out. By default, all the extra modules tend to use the same layout file to render a html, but for view helpes, it searches it's own folder.
In my case, I made a view helper, to load some template's css file. I named it LoadTemplate and placed it inside APPLICATION_PATH."/view/helpers"
It works perfectly, until I browse to a module. Then it gives a error saying
Plugin by name 'LoadTemplate' was not found in the registry; used paths: Custom_View_Helper_: x/x/application/modules/custom/views\helpers/ Zend_View_Helper_: Zend/View/Helper/
It is searching in the wrong folder.
Can't we tell it to search its folder first, and if not found go and find the helper from the default or Application's View Helper?
If your helper is in that directory, make sure it is called Zend_View_Helper_LoadTemplate, the function is called loadTemplate and the file name is LoadTemplate.php
Edit -
Also check out this blog post by Rob Allen: http://akrabat.com/zend-framework/view-helpers-in-modules/