How can I use a image field in a DCE section?
An image element (myImage) can be accessed like this:
<f:for each="{dce:fal(field:'myImage', contentObject:contentObject)}" as="fileReference">
<f:image src="{fileReference.uid}" alt="" treatIdAsReference="1" />
</f:for>
But if I loop through a section (mySection), this code does not work.
Solution after lots of debug:
Use this element for "myImage": File Abstraction Layer (section use only)
<config>
<type>group</type>
<internal_type>db</internal_type>
<appearance>
<elementBrowserType>file</elementBrowserType>
<elementBrowserAllowed>jpg,jpeg,png,gif</elementBrowserAllowed>
</appearance>
<allowed>sys_file</allowed>
<size>1</size>
<minitems>1</minitems>
<maxitems>1</maxitems>
<show_thumbs>1</show_thumbs>
</config>
Use this template code
<f:for each="{field.mySection}" as="teaserbox">
<f:image src="{teaserbox.image}" alt="" />
{teaserbox.text}
</f:for>
You have to remove treatIdAsReference="1" - it will cause this error:
No file usage (sys_file_reference) found for given UID.
This is not the 100% perfect solution, as you don't have the fields like alt, but it works. Better solutions are welcome!
This was not possible in older DCE versions. In the newer ones you can choose FAL Image for Section Configuration. That looks like this:
<config>
<type>group</type>
<internal_type>db</internal_type>
<appearance>
<elementBrowserType>file</elementBrowserType>
<elementBrowserAllowed>jpg,jpeg,png,gif</elementBrowserAllowed>
</appearance>
<allowed>sys_file</allowed>
<size>5</size>
<minitems>0</minitems>
<maxitems>5</maxitems>
<show_thumbs>1</show_thumbs>
</config>
And in your template this should work:
<f:for each="{item.image -> dce:explode()}" as="imageUid">
<f:image src="file:{imageUid}"/>
</f:for>
//this is file upload control with little changes
<config>
<type>group</type>
<internal_type>db</internal_type>
<appearance>
<elementBrowserType>file</elementBrowserType>
<elementBrowserAllowed>jpg,jpeg,png,gif</elementBrowserAllowed>
</appearance>
<allowed>sys_file</allowed>
<size>5</size>
<minitems>0</minitems>
<maxitems>5</maxitems>
<show_thumbs>1</show_thumbs>
<dce_load_schema>1</dce_load_schema>
<dce_get_fal_objects>1</dce_get_fal_objects>
It will look like
In Dce backend it will look like below image
In my case it will look like this
<f:for each="{field.contentBoxes}" as="contentbox">
<div class="col-lg-4 col-md-4 col-sm-6">
<div class="choose__item">
<f:for each="{contentbox.icon}" as="image">
<f:image image="{image}" />
</f:for>
<f:format.html>{contentbox.content}</f:format.html>
</div>
</div>
</f:for>
Now In your case you should try like this
<f:for each="{field.mySection}" as="teaserbox">
<f:for each="{teaserbox.image}" as="img">
<f:image image="{img}" />
</f:for>
{teaserbox.text}
</f:for>
Related
I am using TYPO3 9, News Plugin (News system).
I am looking for a way to group news articles by year, like this:
2019
--------
article 1
article 2
article 3
--------
2018
--------
article 1
article 2
...
I can't find an easy solution for this and find it hard to believe that the only way to implement this is to edit TYPO3's source code...
Can anyone help?
-------------------------- Edit
Fixed and working code suggested by Bernd Wilke:
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers"
xmlns:n="http://typo3.org/ns/GeorgRinger/News/ViewHelpers"
data-namespace-typo3-fluid="true">
<f:layout name="General" />
<!--
=====================
Templates/News/List.html
-->
<f:section name="content">
<!--TYPO3SEARCH_end-->
<f:if condition="{news}">
<f:then>
<f:variable name="oldYear">2010</f:variable>
<f:for each="{news}" as="newsItem" iteration="iterator">
<f:variable name="currentYear"><f:format.date format="%Y">{newsItem.datetime}</f:format.date></f:variable>
<f:if condition="{oldYear} < {currentYear}">
<hr />
<h3>{currentYear}</h3>
<hr />
</f:if>
<f:render partial="List/Item" arguments="{newsItem: newsItem,settings:settings,iterator:iterator}" />
</f:for>
</f:then>
<f:else>
<div class="alert ">
<f:translate key="list_nonewsfound" />
</div>
</f:else>
</f:if>
<!--TYPO3SEARCH_begin-->
</f:section>
</html>
However, I award this question to Georg Ringer as his solution was working right away.
Of course this is possible by fluid by using the ViewHelper f:groupedFor, see official documentation.
There is also an example in the docs of the news extension. So the example should work like that
<f:groupedFor each="{news}" as="groupedNews" groupBy="yearOfDatetime" groupKey="year">
<div style="border:1px solid blue;padding:10px;margin:10px;">
<h1>{year}</h1>
<f:for each="{groupedNews}" as="newsItem">
<div style="border:1px solid pink;padding:5px;margin:5px;">
{newsItem.title}
</div>
</f:for>
</div>
</f:groupedFor>
however I also want to warn about the following
Keep an eye on performance!
To be able to group the records, fluid
will load every record itself and groups those afterwards. If you plan
to group many records just for getting something like a count, maybe
it is better to fire the query directly and don’t use fluid for that.
However if the result is on a cacheable page, the issue is only relevant on the first hit.
There is no typoscript option for grouping like this.
But you can do it in FLUID:
Copy the template files for news listing to your (site) extension and modify it according to your needs: build in a group processing.
<f:variable.set name="oldYear">0000</f:variabel.set>
<f:for each="{news}" as="newsItem" iteration="iterator">
<f:variable.set name="currentYear">{newsItem.datetime->f:format.date("Y")}</f:varaible.set>
<f:if condition="{oldYear} == {currentYear}">
<hr />
<h3>{currentYear}</h3>
<hr />
<f:variable.set name="oldYear">{currentYear}</f:variable.set>
</f:if>
<f:render partial="List/Item" arguments="{newsItem: newsItem,settings:settings,iterator:iterator}" />
</f:for>
You might use one of the viewhelpers mentioned in this answer or this answer.
currently I'm trying to split up the topnews from regular news within a tx_news template. I need to insert a subheadline between topnews and the regular news.
So is there a chance to split the regular template?
<f:section name="content">
<!--TYPO3SEARCH_end-->
<f:for each="{newsItem.categories}" as="category" iteration="iteratorCategories">
<div class="{category.title}"></div>
</f:for>
<f:if condition="{news}">
<f:then>
<div class="news-list-view">
<f:if condition="{settings.hidePagination}">
<f:then>
<f:for each="{news}" as="newsItem" iteration="iterator">
<f:render partial="List/Item" arguments="{newsItem: newsItem,settings:settings,iterator:iterator}" />
</f:for>
</f:then>
<f:else>
<n:widget.paginate objects="{news}" as="paginatedNews" configuration="{settings.list.paginate}" initial="{offset:settings.offset,limit:settings.limit}">
<f:for each="{paginatedNews}" as="newsItem" iteration="iterator">
<f:render partial="List/Item" arguments="{newsItem: newsItem,settings:settings,iterator:iterator}" />
</f:for>
</n:widget.paginate>
</f:else>
</f:if>
</div>
</f:then>
<f:else>
<div class="no-news-found">
<f:translate key="list_nonewsfound" />
</div>
</f:else>
</f:if>
<!--TYPO3SEARCH_begin-->
<div class="showmorenews">
<span><f:translate key="loadmore" /></span>
</div>
</f:section>
thanks a lot
The easiest thing would be to split that into 2 plugins, one to render only top news and one which only renders non-top news.
In the template, you can e.g check the {demand} property to know which plugin renders what or by using a custom layout.
I try to output 1 random image with VHS (version 2.4.0) RandomViewHelper v:iterator.random.
This is my code:
{namespace flux=FluidTYPO3\Flux\ViewHelpers}
{namespace v=FluidTYPO3\Vhs\ViewHelpers}
<f:layout name="Content" />
<f:section name="Configuration">
<flux:form id="random-image" label="Random Image" options="{icon: 'Icons/Content/Example.gif', group: 'Joya'}">
<flux:field.input name="classname" label="Classname" />
</flux:form>
<flux:form.section name="images" label="Images">
<flux:form.object name="image" label="Image">
<flux:field.file name="imagesrc" label="Image" allowed="png,jpg" maxItems="1" size="1" />
</flux:form.object>
</flux:form.section>
</f:section>
<f:section name="Preview">
Random Image
</f:section>
<f:section name="Main">
<div class="random-image">
<v:iterator.random as="img" subject="{images}">
{img.image.imagesrc}
</v:iterator.random>
</div>
</f:section>
I added 3 images to test, but it always outputs the same image.
Edit: the output of random is cached. So it outputs another image after the cache is cleared.
Can I disable the cache just for this line of code?
https://fluidtypo3.org/viewhelpers/vhs/2.4.0/Iterator/RandomViewHelper.html
The solution is to use the VHS ViewHelper v:render.uncache and creatre a partial with the part that shall not be cached. Its not the best solution as you need an extra file. But right now the only other way I can think of is to use some Typoscript, and thats also something I want to avoid.
Another approach is to load the image true an ajax call, this way you can cache the page, but not the random image.
I try to create a Content Element to create links to other languages. I think this is possible with just a content element and I do not need a own view helper for this.
What I have so far:
{namespace flux=FluidTYPO3\Flux\ViewHelpers}
{namespace v=FluidTYPO3\Vhs\ViewHelpers}
<f:layout name="Content" />
<f:section name="Configuration">
<flux:form id="landingpage-language" label="Landingpage Language" options="{icon: 'Icons/Content/Example.gif', group: 'My Ele'}">
<flux:field.input name="title" label="Title"/>
</flux:form>
<flux:form.section name="languages" label="Languages">
<flux:form.object name="language" label="Language">
<flux:field.input name="languagename" label="Language Visible Name"/>
<flux:field.select name="language" label="System Language" items="{
0:{0:'English',1:'&L=1'},
1:{0:'German',1:'&L=2'}
}" />
<flux:field.input name="url" label="URL">
<flux:wizard.link/>
</flux:field.input>
</flux:form.object>
</flux:form.section>
</f:section>
<f:section name="Preview">
Preview
</f:section>
<f:section name="Main">
<h2>{title}</h2>
<ul class="languages">
<f:for each="{languages}" as="langele">
<li><v:link.typolink configuration="{parameter: langele.language.url, additionalParams: langele.language.language}">{langele.language.languagename} {langele.language.language}</v:link.typolink></li>
</f:for>
</ul>
</f:section>
This works but I have 2 problems I can't solve yet:
1. additionalParams
Right now the select items have the values like &L=1. I had to do it this way cause I was not able to add the &L= directly in the typolink configuration. What I would like to have is something like that:
<v:link.typolink configuration="{parameter: langele.language.url, additionalParams: '&L='langele.language.language}">
With this I could have just the ID in the select-items.
Is this possible and if so, how?
2. select items Query
The documentation says it is possible to fill the items of the flux:field.select with a query. But I can not find any example. What I would like to have is all the languages configured in typo3 in this select-box.
Is this possible and if so, how?
something correction in fluxform:
<flux:field.select name="language" label="System Language"
items="{1:'English',2:'German'}" />
you can use fluid typolink instead of vhs viewhelper
<f:for each="{languages}" as="langele">
<li><f:link.typolink parameter="{langele.language.url}" additionalParams="&L={langele.language.language}">{langele.language.languagename} {langele.language.language}</f:link.typolink></li>
</f:for>
But as per your need, I suggest to you use fluid page link:
<f:for each="{languages}" as="langele">
<li><f:link.page pageUid="{langele.language.url}" additionalParams="{L:'{langele.language.language}'}">{langele.language.languagename} {langele.language.language}</f:link.page></li>
</f:for>
Is there any possibilities tu use something like the alternating template parts in tx_news extension? In standard tt_news template I used to use <!-- ###NEWS_1###--> <!-- ###NEWS_2###--> <!-- ###NEWS_3###--> etc. In tx_news everything is in Fluid and I don't see anything similar to alternating template parts in manual.
Ok, again as answer:
You can just do this in fluid, there is no need for a specific feature. The news are rendered in a for-loop, which provides a variable with the current index, see the documentation.
Use the loop index modulo your number of different templates to render news differently in an alternating way. The iteration-variable provides some more subproperties that you can use for controlling the output. To see them all, use <f:debug>{iterator}</f:debug>.
For example, in the list-view of EXT:news you can do this to get three alternating templates, each one represented by a partial. Only the relevant inner loop is shown:
<f:for each="{news}" as="newsItem" iteration="iterator">
<f:if condition="{iterator.index} % 3 == 0">
<f:render partial="List/Item_Layout1" arguments="{newsItem: newsItem,settings:settings,iterator:iterator}" />
</f:if>
<f:if condition="{iterator.index} % 3 == 1">
<f:render partial="List/Item_Layout2" arguments="{newsItem: newsItem,settings:settings,iterator:iterator}" />
</f:if>
<f:if condition="{iterator.index} % 3 == 2">
<f:render partial="List/Item_Layout3" arguments="{newsItem: newsItem,settings:settings,iterator:iterator}" />
</f:if>
</f:for>
If you have EXT:vhs installed with namespace shortcut v (very good extension!), this can be done a bit more elegant:
<f:for each="{news}" as="newsItem" iteration="iterator">
<v:switch value="{iterator.index} % 3">
<v:case value="0" break="true">
<f:render partial="List/Item_Layout1" arguments="{newsItem: newsItem,settings:settings,iterator:iterator}" />
</v:case>
<v:case value="1" break="true">
<f:render partial="List/Item_Layout2" arguments="{newsItem: newsItem,settings:settings,iterator:iterator}" />
</v:case>
<v:case value="2" break="true">
<f:render partial="List/Item_Layout3" arguments="{newsItem: newsItem,settings:settings,iterator:iterator}" />
</v:case>
</v:switch>