Open jensscherbl opened 9 months ago
The hard thing here is changing the behavior while keeping the breaking change small. As it is used in various places where people currently are including the assets/
part (e.g. custom Panel assets).
Cleanest way would be to use the assets root and only path the relative part to that. But this is also the one with the larger breaking change.
Hey, thanks for looking into this (even though it’s only a minor issue).
Maybe it can be multiple separate fixes?
I mean, not using the configured assets-root is actually the smallest issue, so this could be another change for the longer-term.
Returning an actually working media URL, on the other hand, could be done without breaking changes, I guess?
Description
Just stumbled upon that same issue and it still doesn’t seem to be resolved in 4.1.
What I’m trying to do
I have stylesheets under
/assets/styles
in my setup and want to add a hash to the URL for cache busting. I know that there are two plugins available for exactly this and I also have my own workaround, but having broken features like this in the codebase leaves me with a somewhat uneasy feeling.Expected behavior
My understanding of the
Asset
class from its name and description is that I can use it for all my static assets, like fonts, images, stylesheets, etc. So in my controller or template, I callasset('assets/styles/all.min.css')->mediaUrl()
and (based on the name of the method) expect to get a URL (including themediaHash
) to a copy of that file in the media folder.However, there are several issues at the moment:
/media/assets/assets/styles/all.min.css
, since it’s automatically prefixed withassets/
.assets('styles/all.min.css')->mediaUrl()
, it can’t find the file to calculate themediaHash
because the path will only be prefixed withassets/
after calculating themediaHash
./media/assets/styles
in this scenario) and callassets('styles/all.min.css')->mediaUrl()
orassets('assets/styles/all.min.css')->mediaUrl()
, it can’t find the file to calculate themediaHash
.assets('media/assets/styles/all.min.css')->mediaUrl()
the file can be found and themediaHash
can be calculated, but the resulting path is wrong since it will be prefixed withmedia/assets/media/assets/styles/...
.Proposed solution
Not sure if this has any unwanted side effects, but my naive take on how this should work would be:
Asset
class.mediaPath
. Keep prefixing themediaPath
withassets/
.Asset::mediaUrl()
is called.To reproduce
See description.
Your setup
Kirby Version
4.1
PHP Version
8.3