vhs
vhs copied to clipboard
v:page.resources.fal optional fallback for languages
I've seen a few issues here regarding this, but non specified the following use-case: We're currently having 3 languages, with English as default, German secondary etc...
For most pages we'd want to use the default media image of the current page for all languages, but only if there is no image specified for the translation. We tried a few things but nothing worked as expected.
That's our current try:
<f:if condition="{page.media} >= 1">
<f:then>
<v:page.resources.fal table="pages" field="media" uid="{page.uid}" as="resources" slide="-1">
<f:for each="{resources}" as="resource">
<f:image src="{resource.id}" treatIdAsReference="1" width="1400" height="350c" class="heroimg" />
</f:for>
</v:page.resources.fal>
</f:then>
<f:else>
<v:page.resources.fal table="pages_language_overlay" field="media" uid="{page.uid}" as="resources" slide="-1">
<f:for each="{resources}" as="resource">
<f:image src="{resource.id}" treatIdAsReference="1" width="1400" height="350c" class="heroimg" />
</f:for>
</v:page.resources.fal>
</f:else>
</f:if>
But that does not output anything on the translated page. How could we accomplish this?
Is this actually a bug? The following should work for all translations, when a header image is defined in the default language.
<v:page.resources.fal table="pages" field="media" uid="{page.uid}" as="resources" slide="-1">
<f:for each="{resources}" as="resource">
<f:image src="{resource.id}" treatIdAsReference="1" width="1400" height="350c" class="heroimg" />
</f:for>
</v:page.resources.fal>
I'm having the exact same issue. Did you find a solution for this? I know I can add the image manually in the translated page settings, but it makes no sense to not be able to just show the original image.
Unfortunately not. We had to use an extra column for the header image as a workaround. No chance of getting the media field "translated".
I solved this by adding a custom view helper before my <v:page.resources.fal>, which sets the global language to the default one if there are no images found:
$GLOBALS['TSFE']->sys_language_uid = 0;
After my loop I immediately set this back to the original language_uid.
Ugly, but works.
@tkrebs Could you share your solution, please? We are having this issue with other projects as well. I'd rather have an ugly workaround than to create a new column in the backend for every project.
As said, I am setting the global language uid to 0 before I call {v:page.resources.fal}. I used a custom PHP code parser view helper for this, though a more specialized helper would definitely be more secure.
{c:php(code: '$GLOBALS[\'TSFE\']->sys_language_uid = 0;')}
{v:page.resources.fal(table: 'pages', field: 'media', as: 'images')}
[...]
<f:for each="{images}" as="image" iteration="imageIteration">
[...]
</f:for>
[...]
{c:php(code: '$GLOBALS[\'TSFE\']->sys_language_uid = {languageCode};')}
The {languageCode} variable is injected via TypoScript.
Uff, that's really nasty. :D Thanks for that, though.
This is no longer a problem - v:page.resources.fal will consult the page overlay to look for a translated version of the associated FAL records. If no such translated records are found, it will default to using the untranslated version of associated FAL records; including when using "sliding" to fetch from parent page(s).
Assuming I read the report correctly, that is the exact desired behavior?