How to force TYPO3 v12 to use the extension's real name when symlinking it in _assets?

223 views Asked by At

Starting with TYPO3 v12 extensions are no longer inside the webserver's document root and the Resources/Public folder is symlinked to _assets/SOME-RANDOM-HASH. When adding CSS, JavaScripts or images within the template by TypoScript or Fluid you can use EXT:my_extension_name to link into the extensions Resources/Public folder but what possibilities or strategies are there when you're using an external JavaScript or need to link to an image from an HTML content element?

Because extensions are used to define the websites 'theme' or 'template' as well, I see no security issue when using the real extension name for the symlink in _assets for these 'extensions'. So is there an option (for example within the composer.json) to use the extension's real name when symlinking it?

Are there any 'best practices' on linking to static files that are part of the website's theme?

1

There are 1 answers

0
Garvin Hicking On

There are some ways:

  • Create a custom middleware that "listens" in specific URLs and passthrough your static content (i.e. listen on "/static/yourfile.ext", use fpassthrough or the likes; ensure security, make sure no files outside are resolved)
  • Create a middleware that does search+replace before content is emitted, replacing "STATIC:..." or any other syntax be resolving to replace it with EXT:... syntax (and thus getting the "hashed" URL). That would help with content elements.
  • Actually move statically referenced content to a custom file location like /static/ (or within fileadmin)
  • Create a symlink like /sitepackage/ to your extensions Resources/Public directory, and reference that.
  • use the DOM of your page, and let fluid/typoscript assign a variable with the asset URL/location to a DOM element (like <body data-asset="...">). Then use JavaScript to retrieve the DOM attribute value, and use it for what you want to achieve.

HTH!