Search code examples
typo3fluidtypo3-9.xtypo3-extensions

TYPO3 extension - f:uri.resource returns wrong path


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.


Solution

  • 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.