如何在 Fluid 和 tx-news 中用图像源填充 Flexsliders data-thumb 属性?
How to fill Flexsliders data-thumb attribute with image source in Fluid and tx-news?
我正在实现一个基于 TYPO3 扩展 "news" 和 Flexslider 的新闻滑块。新闻滑块包含缩略图预览图像,这些图像通过包含 URL 的 "data-thumb" 属性加载到滑块中的每个图像。如何在 Fluid 和新闻扩展中获取 URL?
我尝试了以下操作,但出现错误:
<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>
滑块中一个对象的完整部分如下所示:
<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>
任何提示我做错了什么?我知道还有新闻滑块扩展,但我不想进一步依赖另一个扩展。
看来括号设置有误,您必须 "escape" 左括号和右括号。
试试这个:
<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>
更新:
这是你的全部部分。你必须使用 {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>
我在sections
的帮助下解决了。就像扩展程序 t3newsslider
一样。
我将此添加到部分文件的末尾:
<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>
然后我这样引用:
<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>
而且有效。
我正在实现一个基于 TYPO3 扩展 "news" 和 Flexslider 的新闻滑块。新闻滑块包含缩略图预览图像,这些图像通过包含 URL 的 "data-thumb" 属性加载到滑块中的每个图像。如何在 Fluid 和新闻扩展中获取 URL?
我尝试了以下操作,但出现错误:
<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>
滑块中一个对象的完整部分如下所示:
<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>
任何提示我做错了什么?我知道还有新闻滑块扩展,但我不想进一步依赖另一个扩展。
看来括号设置有误,您必须 "escape" 左括号和右括号。
试试这个:
<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>
更新:
这是你的全部部分。你必须使用 {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>
我在sections
的帮助下解决了。就像扩展程序 t3newsslider
一样。
我将此添加到部分文件的末尾:
<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>
然后我这样引用:
<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>
而且有效。