Reputation: 189
I'm trying to access fluid page configuration inside a template.
In detail: I added a selectfield to my page layout
<flux:flexform.field.select name="pageIcon" items="{
0: {0: '{f:translate(key: \'pageIconNone\')}', 1: ''},
1: {0: '{f:translate(key: \'pageIconFacebook\')}', 1: 'fa-facebook-square'},
2: {0: '{f:translate(key: \'pageIconFlickr\')}', 1: 'fa-flickr'},
3: {0: '{f:translate(key: \'pageIconGooglePlus\')}', 1: 'fa-google-plus-square'}
}"/>
So far so good. Now I render a menu an want to access this field pageIcon
<v:page.menu.directory pages="{settings.pid.socialMenu}" useShortcutData="TRUE" classFirst="first" classLast="last">
<f:for each="{menu}" as="mainPage" iteration="iteration">
<a href="{mainPage.link}" class="{mainPage.class}"><i class="fa {mainPage.pageIcon} fa-2x"></i><b>{mainPage.title}</b></a>
</f:for>
</v:page.menu.directory>
But this does not work. After some debugging I noticed, that this configuration seems to be stored in tx_fed_page_flexform which holds an XML array.
How can I access the XML values inside my fluid template?
Markus
Upvotes: 3
Views: 1840
Reputation: 4261
The easiest way:
https://fluidtypo3.org/viewhelpers/flux/master/Form/DataViewHelper.html
<flux:flexform.data table="pages" field="tx_fed_page_flexform" uid="{pageUid}" as="pageData">
<a href="#">{pageData.pageIcon}</a>
</flux:flexform.data>
The reason for not extracting this data always, is simply for performance. There is another way which you may not be aware of:
<flux:flexform.field.select name="pages.pageIcon" items="{...}" />
If you name your field thusly (the pages.
prefix is the key since we are using the pages
DB table) your value will be saved into a field in the record itself (a field you must then add in the SQL schema / TCA, and enable value sliding in the rootline if you desire it). If a field with this prefix is saved, Flux will insert its value directly into the pages record which means you can immediately access it using for example {pageVariable.icon}
without the need for the flux:flexform.data
ViewHelper.
For more recent version of Flux, try:
<flux:form.data table="pages" field="tx_fed_page_flexform" uid="{pageUid}" as="pageData">
<a href="#">{pageData.pageIcon}</a>
</flux:form.data>
Upvotes: 8