Access flux fields from another Fluidtypo3 FCE element (flux, fluidcontent, vhs) - typo3

I'm trying to access the settings of a Fluidtypo3 FCE element. My FCE is a news article that I want to include in another FCE, which is a slider. The slider only has one field and the configuration is the following:
<flux:field.relation
name="articles"
label="News-Beitrag"
multiple="true"
size="6"
table="tt_content"
condition="AND tt_content.pid = {record.pid} AND CType = 'fluidcontent_content' AND colPos = 1 AND sys_language_uid = {record.sys_language_uid}"
minItems="1"
maxItems="10"
renderMode="default"
/>
This configuration works, I can select all my news FCE's as a relation. The field articles saves the uid's of all referenced FCE's. Now I am trying to use these uid's to receive the content. Right now my code is the following:
<f:section name="Main">
<f:if condition="{articles}">
{v:iterator.explode(content: '{articles}', glue: ",", as: 'articles')}
{v:content.get(contentUids: "{articles}", render: 0) -> v:variable.set(name: 'slides')}
<f:for each="{slides}" as="element">
</f:for>
</f:if>
</f:section>
The <v:content.get> ViewHelper gets the tt_content record as it is recorded in the database. The flux settings are stored in XML-Format in the field pi_flexform. I am trying to access those specific flux settings one by one and not just the whole pi_flexform field in xml format.
I've looked for ViewHelpers that can convert XML to an Array and tried many other things, but nothing worked for me. I am grateful for any ideas how to solve this problem.

<flux:form.data> is the Viewhelper you seek. You can use it like this:
<f:for each="{slides}" as="element">
<flux:form.data table="tt_content" field="pi_flexform" record="{element}" as="flexformData">
<!-- Do stuff with flexformData -->
</flux:form.data>
</f:for>

Related

TYPO3 : send data from extension to the backend layout

I made an extension which display some data and I need to send them to my Layout.
In my file list.html I made a left column with some data, but finally I need this column in my layout.
there is some code :
Layouts/MyLayout.html
<f:render partial="Structure/Header" arguments="{_all}"/>
<f:render partial="Menus/Main" arguments="{_all}"/>
<!--the left column should be here -->
<f:render section="default" />
List.html
<f:layout name="Default"/>
<f:section name="main">
<aside>
<h2>Title</h2>
<ul>
<f:for each="{Mydata}" as="data">
<li>{data.title}</li>
</f:for>
</ul>
</aside>
</f:section>
That's why I would need to retrieve my extension data in my layout. It is possible to get I ?
If it's not possible, it is possible to get in list.html the name of the actual backend layout with some typoscript ?
There are multiple options to handle whether there are data for an additional column in layout.
first:
Even if in FLUID the files are stored in three folder (Layouts/, Partials/, Templates/) you are not forced to use it in that way. Meaning: you also can decide the layout in the template files.
In the default layout you just render a mainsection (from the template file). And in the different templates you decide whether a side column exist.
second:
extension data can be provided in multiple ways:
You can do the rendering completely in typoscript - or you use a content element with a plugin. The later would be more transparent for editors.
In your case you can provide a different BackEnd layout where editors can put a plugin in the additional column for that special 'layout'.
The rendering only occurs if that 'layout' is selected and a plugin is stored in that column.

Display full name of logged in TYPO3 frontend user in Fluid

The task is pretty simple: I want to display the full name (first- and lastname) of the current TYPO3 frontend user in Fluid. But somehow, TYPO3 (version 9.5) or Fluid seems to cache data, so a logged in frontend user sometimes sees the name of other another logged user.
Current implementation:
TypoScript:
lib.username = USER_INT
lib.username.userFunc = Vendor\Extension\UserFunc\Username->getUsername
This is a USER_INT, so the output should always be uncached.
Fluid Layout - Default.html:
<f:render partial="Header" section="Top" />
Fluid Partial - Header.html:
<f:section name="Top">
<img src="logo.png">
<f:render partial="Navigation" />
</f:section>
Fluid Partial - Navigation.html
<f:security.ifAuthenticated>
<f:then>
<p>Logged in as: <f:cObject typoscriptObjectPath="lib.username" /></p>
</f:then>
<f:else>
<p>Not logged in</p>
<f:else>
</f:security.ifAuthenticated>
Why does the result of the cObject get cached? Should'nt this always be calculated per request, because lib.username is a USER_INT? I also tried to add a f:cache.disable ViewHelper to the template with no success.
In order to resolve the problem I refactored it to fetch the full name of the fe_user using a JavaScript XHR request to a simple PSR-15 middleware. Is this really the only suitable solution or am I missing something?
Update 17.12.2020
This all works fine. I just spotted a typo in my userFunc, which resulted in the unexpected behavior.
This happens because TYPO3 cache works with frontend user groups, not frontend users. So you will see results cached for the list of user's groups rather than the current user.
Use <v:render.uncache> ... </v:render.uncache> from EXT:vhs to render that part of code uncached. Alternatively you can modify TYPO3 caching to use the current user but this may decrease cache performance and seriously increase amount of cached items.
Beware, that there is a caching problem even with USER_INT and COA_Int see https://forge.typo3.org/issues/37988
You could use only TypoScript for that like:
lib.username = COA_INT
lib.username {
10 = TEXT
10.data = TSFE:fe_user|user|first_name
10.wrap = |
20 = TEXT
20.data = TSFE:fe_user|user|lastname_name
}
Why use TypoScript? It is very limited on what it can bring back. I just finished a tutorial where you can use a ViewHelper to add an ExtBase variable which assigns the whole user object in the FrontEnd and you can use it wherever you want with all it's relations, even the image, which is difficult to get via TypoScript.
TYPO3 tutorial
Best regards
share edit delete flag

TYPO3 tx_news: category-specific CSS styling

I´m using a Typo3 V9 together with the tx_news extension by G. Ringer. The extension is working very well, there´s only one feature I didn´t found:
Having different news categories, I want to style the teasertext in list view different for each category.
So I need a CSS class varying for every category (best would be the UIDs of the category records mapped directly into a css class). How can I accomplish this?
get inspired by the partial for the categories (ext:news/Resources/Private/Partials/Category/Items.html):
<f:section name="category-classes">
<f:for each="{categories}" as="category"> cat-class-{category.uid}</f:for>
</f:section>
and build it into your template (list, detail, ...)
e.g. the list item (ext:news/Resources/Private/Partials/List/Items.html) modify line 8 from
<div class="article articletype-{newsItem.type}{f:if(condition: newsItem.istopnews, then: ' topnews')}" itemscope="itemscope" itemtype="http://schema.org/Article">
to
<div class="article articletype-{newsItem.type}{f:if(condition: newsItem.istopnews, then: ' topnews')}{f:render(section:'category-classes', arguments:'categories:newsItem.categories')}" itemscope="itemscope" itemtype="http://schema.org/Article">

TYPO3 fluid_styled_content - Menu when using gridelements

how can i build a TYPO3 special-Menu in fluid with tt_content Header Elements, not the "pages" ?
https://docs.typo3.org/typo3cms/extensions/fluid_styled_content/7.6/ContentElements/Menu/Index.html
The Type-3 is a good Example, but i can only selected in the BE the Pages, not the tt_content - Elements.
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" xmlns:ce="http://typo3.org/ns/TYPO3/CMS/FluidStyledContent/ViewHelpers" data-namespace-typo3-fluid="true">
<ce:menu.list pageUids="{pageUids}" as="pages">
<f:if condition="{pages}">
<ul class="ce-menu ce-menu-3">
<f:for each="{pages}" as="page">
<ce:menu.section pageUid="{page.uid}" as="contentElements" type="header">
<f:if condition="{contentElements}">
<f:for each="{contentElements}" as="contentElement">
<li>
<f:link.page pageUid="{page.uid}" section="c{contentElement.uid}">
{contentElement.header}
</f:link.page>
</li>
</f:for>
</f:if>
</ce:menu.section>
</f:for>
</ul>
</f:if>
</ce:menu.list>
</html>
I suppose you get back content elements which have "Show in Section Menus" enabled, and have the header filled and not hidden. The menu.section viewhelper does not have the possibility to filter on content element type. The type="header" argument of the view helper is not a filter for the content element type, but checks if there is a visible header_layout and the header field is not empty. I agree, the argument name type is misleading.
If you want to filter on content type (CType), add an extra "if" statement, filtering on {contentElement.CType} == header during the iteration of the content elements
<f:for each="{contentElements}" as="contentElement">
<f:if condition="{contentElement.CType} == 'header'">
<li>
<f:link.page pageUid="{page.uid}" section="c{contentElement.uid}">
{contentElement.header}
</f:link.page>
</li>
</f:if>
</f:for>
Better would be to write your own view helper for this, if you have the knowledge to do it.
First of all you should rename your question so it is clear that you want to create a content menu that works with grid_elements
I had the same problem and could not find another way but to create a small extension for that purpose since you have to modify the search query for the content. You can find it here: https://typo3.org/extensions/repository/view/gridelements_content_menu
There is currently no manual, just install the extension and include the static TS in your template. The resulting Menu might not be sorted right if your content elements are nested deeper than one level with grid_elements

Is it possible to set by fluid a argument that the typo3 backend uses as input

In the typo3 template I'm using the following line to get the last 5 added items from the backend and this works.
<f:cObject typoscriptObjectPath="lib.lastaddeditmes" />
Only the number of item I want to have it flexible and set in the fluid template. So for example like below where the qty is set to three, is this possible?
<f:cObject typoscriptObjectPath="lib.lastaddeditmes(3)" />
You can't do that in the view, instead you can make a copy of lib.lastaddeditmes in TypoScript and then use it in other place like:
lib.lastaddeditmesOnlyThree < lib.lastaddeditmes
lib.lastaddeditmesOnlyThree.someSetting.items = 3
and in view:
<f:cObject typoscriptObjectPath="lib.lastaddeditmesOnlyThree" />
Remember that TypoScript is just a configuration syntax (not programming language) so it shouldn't give you any huge performance drop.