In my extensions Resource/Public
folder, I have an image. I want to render this image using the <f:image>
-ViewHelper, using the image
-attribute, which takes a FAL file object. How do I do that?
It's not that I can't use src
, I just don't want to - one less branch in my code.
I'm using TYPO3 6.2.14 and the FluidTYPO3-ecosystem.
I've gotten an answer in Slack, by Helmut Hummel: It is only possible when using the compatibility layer.
He wrote a blog post about this. The relevant section is this:
Static Resources
I would define only two rules for how to (currently) use static resources:
- Don’t use them with the image view helper
- Put them into an extension in the Resources/Public folder
If you follow these rules, you will have less trouble.
We currently don’t have an API to deal with static resources and the FAL API can only deal with them in a backwards compatibility layer (which you should avoid using, really!). This is why you should currently follow rule 1 (Once we have objects that describe static resources properly, we might abondon rule 1).
You need to follow rule 2 to take advantage of a not well known Fluid view helper, the resource uri view helper. You can use it to e.g. show an image from a site package (my_site/Resources/Public/Images/logo.png) like that:
<img src="{f:uri.resource(path:'Images/logo.png', extensionName:'my_site')}" width="200" />
Note that I didn’t use the image view helper here, but the plain img html tag and used the resource view helper in inline notation to automatically calculate the path to the web root for that image. Also note, that the view helper expects the static resources to be placed in the Resources/Public directory.