Reputation: 85
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.
Upvotes: 0
Views: 485
Reputation: 85
I solved it with the help of sections
. In the same way like the extension t3newsslider
did it.
I added this to the end of my partial file:
<f:section name="MediaElementThumbSrc">
<f:if condition="{newsItem.mediaPreviews}">
<f:then>
<f:alias map="{mediaElementSrc: '{newsItem.mediaPreviews.0}'}">
<f:uri.image src="{mediaElementSrc.uid}" treatIdAsReference="1"
width="{f:if(condition: settings.media.maxWidth, then: settings.media.maxWidth, else: settings.list.media.image.newsSliderMaxWidth)}"
height="{f:if(condition: settings.media.maxHeight, then: settings.media.maxHeight, else: settings.list.media.image.newsSliderMaxHeight)}" />
</f:alias>
</f:then>
<f:else>
<f:if condition="{settings.displayDummyIfNoMedia}">
<f:uri.image src="{settings.list.media.dummyImage}"
width="{f:if(condition: settings.media.maxWidth, then: settings.media.maxWidth, else: settings.list.media.image.newsSliderMaxWidth)}"
height="{f:if(condition: settings.media.maxHeight, then: settings.media.maxHeight, else: settings.list.media.image.newsSliderMaxHeight)}" />
</f:if>
</f:else>
</f:if>
</f:section>
And then I referenced to this like this:
<li class="item itemtype-{newsItem.type}{f:if(condition: newsItem.istopnews, then: ' topnews')}"
data-thumb="{f:render(section:'MediaElementThumbSrc', arguments:'{newsItem:newsItem, settings:settings}')}"
itemscope="itemscope" itemtype="http://schema.org/Article">...</li>
And it works.
Upvotes: 1
Reputation: 2243
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>
Upvotes: 1