0

I am implementing a news slider based on the TYPO3 extension "news" and Flexslider. The news slider contains thumbnail preview images and these images are loaded through the "data-thumb" attribute that contains the URL to each image in the slider. How do I get the URL in Fluid and the news extenstion?

I tried the following but I am getting an error:

<li data-thumb="{f:uri.image(image:mediaElement,title:'{mediaElement.originalResource.title}',alt:'{mediaElement.originalResource.alternative}', maxWidth:'{settings.list.media.image.maxWidth}',maxHeight:'{settings.list.media.image.maxHeight}')}">...</li>

The full partial for one object in the slider looks like this:

<li class="item itemtype-{newsItem.type}{f:if(condition: newsItem.istopnews, then: ' topnews')}" data-thumb="{f:uri.image(image:mediaElement,title:'{mediaElement.originalResource.title}',alt:'{mediaElement.originalResource.alternative}', maxWidth:'{settings.list.media.image.maxWidth}',maxHeight:'{settings.list.media.image.maxHeight}')}" itemscope="itemscope" itemtype="http://schema.org/Article">

    <n:excludeDisplayedNews newsItem="{newsItem}"/>
    <f:if condition="{newsItem.mediaPreviews}">
        <!-- media preview element -->
        <f:then>
            <div>
                <n:link newsItem="{newsItem}" settings="{settings}" title="{newsItem.title}">
                    <f:alias map="{mediaElement: '{newsItem.mediaPreviews.0}'}">
                        <f:if condition="{mediaElement.originalResource.type} == 2">
                            <f:image image="{mediaElement}" title="{mediaElement.originalResource.title}" alt="{mediaElement.originalResource.alternative}" width="{f:if(condition: settings.media.maxWidth, then: settings.media.maxWidth, else: settings.list.media.image.maxWidth)}" height="{f:if(condition: settings.media.maxHeight, then: settings.media.maxHeight, else: settings.list.media.image.maxHeight)}"/>
                        </f:if>
                        <f:if condition="{mediaElement.originalResource.type} == 4">
                            <f:render partial="Detail/MediaVideo" arguments="{mediaElement: mediaElement}"/>
                        </f:if>
                        <f:if condition="{mediaElement.originalResource.type} == 5">
                            <f:image image="{mediaElement}" title="{mediaElement.originalResource.title}" alt="{mediaElement.originalResource.alternative}" width="{f:if(condition: settings.media.maxWidth, then: settings.media.maxWidth, else: settings.list.media.image.maxWidth)}" height="{f:if(condition: settings.media.maxHeight, then: settings.media.maxHeight, else: settings.list.media.image.maxHeight)}"/>
                        </f:if>
                    </f:alias>
                </n:link>
            </div>
        </f:then>
        <f:else>
            <f:if condition="{settings.displayDummyIfNoMedia}">
                <div>
                    <span class="no-media-element">
                        <n:link newsItem="{newsItem}" settings="{settings}" title="{newsItem.title}">
                            <f:image src="{settings.list.media.dummyImage}" title="" alt="" width="{f:if(condition: settings.media.maxWidth, then: settings.media.maxWidth, else: settings.list.media.image.maxWidth)}" height="{f:if(condition: settings.media.maxHeight, then: settings.media.maxHeight, else: settings.list.media.image.maxHeight)}"/>
                        </n:link>
                    </span>
                </div>
            </f:if>
        </f:else>
    </f:if> 
    <div class="flex-caption">
        <h1 class="fvl flex-title">
            <n:link newsItem="{newsItem}" settings="{settings}" title="{newsItem.title}">
                <span itemprop="headline">{newsItem.title -> f:format.crop(maxCharacters: '40', respectWordBoundaries:'1')}</span>
            </n:link>
        </h1>
        <p class="flexslider-subtitle">
            <n:removeMediaTags>
            <f:if condition="{newsItem.teaser}">
                <f:then>
                    <span itemprop="description">{newsItem.teaser -> f:format.crop(maxCharacters: '{settings.cropMaxCharacters}', respectWordBoundaries:'1') -> f:format.stripTags()}</span>
                </f:then>
                <f:else>    
                    <span itemprop="description"></div>{newsItem.bodytext -> f:format.crop(maxCharacters: '{settings.cropMaxCharacters}', respectWordBoundaries:'1') -> f:format.stripTags()}</span>
                </f:else>
            </f:if>
            </n:removeMediaTags>
            <span>
                <n:link newsItem="{newsItem}" settings="{settings}" class="more" title="{newsItem.title}">
                    <f:translate key="more-link"/>
                </n:link>
            </span>
        </p>
    </div>
</li>

Any hint what I am doing wrong? I know that there are also news slider extensions but I don't want to have a further dependency on another extension.

bastians
  • 85
  • 9

2 Answers2

1

It looks like the brackets are set wrong and you have to "escape" the opening ond closing brackets.

Try this:

<li data-thumb="<f:format.raw>{</f:format.raw>
    {f:uri.image(image:mediaElement)},
    title:'{mediaElement.originalResource.title}',
    alt:'{mediaElement.originalResource.alternative}', 
    maxWidth:'{settings.list.media.image.maxWidth}',
    maxHeight:'{settings.list.media.image.maxHeight}'
<f:format.raw>}</f:format.raw>">...</li>

UPDATE:

This is your full partial. You have to use {newsItem.mediaPreviews.0}:

<li class="item itemtype-{newsItem.type}{f:if(condition: newsItem.istopnews, then: ' topnews')}" data-thumb="<f:format.raw>{</f:format.raw>{f:uri.image(image:newsItem.mediaPreviews.0)},title:'{newsItem.mediaPreviews.0.originalResource.title}',alt:'{newsItem.mediaPreviews.0.originalResource.alternative}',maxWidth:'{settings.list.media.image.maxWidth}',maxHeight:'{settings.list.media.image.maxHeight}'<f:format.raw>}</f:format.raw>" itemscope="itemscope" itemtype="http://schema.org/Article">

    <n:excludeDisplayedNews newsItem="{newsItem}"/>
    <f:if condition="{newsItem.mediaPreviews}">
        <!-- media preview element -->
        <f:then>
            <div>
                <n:link newsItem="{newsItem}" settings="{settings}" title="{newsItem.title}">
                    <f:alias map="{mediaElement: '{newsItem.mediaPreviews.0}'}">
                        <f:if condition="{mediaElement.originalResource.type} == 2">
                            <f:image image="{mediaElement}" title="{mediaElement.originalResource.title}" alt="{mediaElement.originalResource.alternative}" width="{f:if(condition: settings.media.maxWidth, then: settings.media.maxWidth, else: settings.list.media.image.maxWidth)}" height="{f:if(condition: settings.media.maxHeight, then: settings.media.maxHeight, else: settings.list.media.image.maxHeight)}"/>
                        </f:if>
                        <f:if condition="{mediaElement.originalResource.type} == 4">
                            <f:render partial="Detail/MediaVideo" arguments="{mediaElement: mediaElement}"/>
                        </f:if>
                        <f:if condition="{mediaElement.originalResource.type} == 5">
                            <f:image image="{mediaElement}" title="{mediaElement.originalResource.title}" alt="{mediaElement.originalResource.alternative}" width="{f:if(condition: settings.media.maxWidth, then: settings.media.maxWidth, else: settings.list.media.image.maxWidth)}" height="{f:if(condition: settings.media.maxHeight, then: settings.media.maxHeight, else: settings.list.media.image.maxHeight)}"/>
                        </f:if>
                    </f:alias>
                </n:link>
            </div>
        </f:then>
        <f:else>
            <f:if condition="{settings.displayDummyIfNoMedia}">
                <div>
                    <span class="no-media-element">
                        <n:link newsItem="{newsItem}" settings="{settings}" title="{newsItem.title}">
                            <f:image src="{settings.list.media.dummyImage}" title="" alt="" width="{f:if(condition: settings.media.maxWidth, then: settings.media.maxWidth, else: settings.list.media.image.maxWidth)}" height="{f:if(condition: settings.media.maxHeight, then: settings.media.maxHeight, else: settings.list.media.image.maxHeight)}"/>
                        </n:link>
                    </span>
                </div>
            </f:if>
        </f:else>
    </f:if> 
    <div class="flex-caption">
        <h1 class="fvl flex-title">
            <n:link newsItem="{newsItem}" settings="{settings}" title="{newsItem.title}">
                <span itemprop="headline">{newsItem.title -> f:format.crop(maxCharacters: '40', respectWordBoundaries:'1')}</span>
            </n:link>
        </h1>
        <p class="flexslider-subtitle">
            <n:removeMediaTags>
            <f:if condition="{newsItem.teaser}">
                <f:then>
                    <span itemprop="description">{newsItem.teaser -> f:format.crop(maxCharacters: '{settings.cropMaxCharacters}', respectWordBoundaries:'1') -> f:format.stripTags()}</span>
                </f:then>
                <f:else>    
                    <span itemprop="description"></div>{newsItem.bodytext -> f:format.crop(maxCharacters: '{settings.cropMaxCharacters}', respectWordBoundaries:'1') -> f:format.stripTags()}</span>
                </f:else>
            </f:if>
            </n:removeMediaTags>
            <span>
                <n:link newsItem="{newsItem}" settings="{settings}" class="more" title="{newsItem.title}">
                    <f:translate key="more-link"/>
                </n:link>
            </span>
        </p>
    </div>
</li>
chris
  • 2,109
  • 2
  • 23
  • 33
  • Thanks for your answer. I tried it, but in the output there is no URL. It looks like this: ```
  • ...
  • ``` It seems, that the Fluid is not rendered. As it is inline, don't I have the use the inline syntax? – bastians Apr 04 '19 at 06:43
  • Are you sure, that you have data for `mediaElement`? Try `{mediaElement}` and see if you get some output. I have tested the above code and it is working for me. – chris Apr 04 '19 at 13:19
  • Sorry, where do I have to place `{mediaElement}` in my template? – bastians Apr 04 '19 at 13:43
  • 1
    @bastians Add it just before your
  • element. If you dont get any output (which I assume), use `{_all}` to see, what data you get.
  • – chris Apr 04 '19 at 15:31
  • Ok, `{mediaElement}` shows `Extbase Variable Dump: NULL`. `{_all}` shows 5 results of the 5 news records I have and there are images behind `falmedia`. Or do I need to check other attributes? Did not see others that could be related to my issue. – bastians Apr 04 '19 at 18:06
  • Go for `falmedia`, that is the one. – chris Apr 04 '19 at 19:26
  • Ok. As there is some output and the HTML output of data-thumb is `data-thumb="{ , title:'', alt:'', maxWidth:'100', maxHeight:'100' }"` I still think that the problem is in my Fluid syntax. – bastians Apr 05 '19 at 06:11
  • See the updated answer with full partial code: you have to use the `{newsItem.mediaPreviews.0}`. – chris Apr 05 '19 at 07:50
  • We are getting closer ;) The output is now `
  • `and I will try to figure out now why it's not rendered correctly yet. But at least the URL is there now! Thanks!
  • – bastians Apr 05 '19 at 10:43