TYPO3 Gridelements render FAL Image using Fluidtemplate - typo3

I'm using TYPO3 8.7 and the latest extension gridelements (8.2.3). Now I want to show/render an image in my FLUIDTEMPLATE.. - but I don't know how?!?
Here's my TypoScript:
tt_content {
gridelements_pi1 = COA
gridelements_pi1 {
20 {
10 {
setup {
SectionColoured < lib.gridelements.defaultGridSetup
SectionColoured {
cObject = FLUIDTEMPLATE
cObject {
file = EXT:myext/.../SectionColoured.html
}
}
}
}
}
}
}
Now, I upload an image (e.g. for background-image) via flexforms, like this:
<backgroundimage type="array">
<TCEforms type="array">
<label>LLL:EXT:autefa/Resources/Private/Language/backend.xlf:gridelements.SectionColoured.flexforms.backgroundimage</label>
<config type="array">
<type>inline</type>
<maxitems>1</maxitems>
<foreign_table>sys_file_reference</foreign_table>
<!--<foreign_field>uid_foreign</foreign_field>-->
<foreign_table_field>tablenames</foreign_table_field>
<foreign_label>uid_local</foreign_label>
<foreign_sortby>sorting_foreign</foreign_sortby>
<foreign_selector>uid_local</foreign_selector>
<foreign_selector_fieldTcaOverride type="array">
<config>
<appearance>
<elementBrowserType>file</elementBrowserType>
<elementBrowserAllowed>jpg,png</elementBrowserAllowed>
</appearance>
</config>
</foreign_selector_fieldTcaOverride>
<foreign_match_fields type="array">
<fieldname>image</fieldname>
</foreign_match_fields>
<appearance type="array">
<newRecordLinkAddTitle>1</newRecordLinkAddTitle>
<headerThumbnail>
<field>uid_local</field>
<height>64</height>
<width>64</width>
</headerThumbnail>
</appearance>
</config>
</TCEforms>
</backgroundimage>
That works so far. How can I use the image in my FLUIDTEMPLATE? The debugger returns 12 on {data.flexform_backgroundimage} ?!
<f:debug>{data.flexform_backgroundimage}</f:debug>
<section class="main-content {data.flexform_farbe}">
<article>
<f:format.raw>{data.tx_gridelements_view_columns.101}</f:format.raw>
</article>
</section>
Debug {data}.. THanks for your help!
pi_flexform => array(1 item)
data => array(1 item)
general => array(1 item)
lDEF => array(2 items)
farbe => array(1 item)
backgroundimage => array(1 item)
vDEF => '12' (2 chars)
Edit: image

It's funny. If I try it with the TYPO3 Fluid ViewHelper:
<section style="background-image:url({f:uri.image(src: '{data.flexform_backgroundimage}', treatIdAsReference: 1)})">
<article>
<f:format.raw>{data.tx_gridelements_view_columns.100}</f:format.raw>
</article>
</section>
I'll get an error You must either specify a string src or a File object.
Now I use vhs:
{namespace v=FluidTYPO3\Vhs\ViewHelpers}
<section style="background-image:url({v:uri.image(src: '{data.flexform_backgroundimage}', treatIdAsReference: 1)})">
<article>
<f:format.raw>{data.tx_gridelements_view_columns.100}</f:format.raw>
</article>
</section>
And everything works .. here's the view helper reference of the vhs extension. Thanks for the helping guys!

Since FAL is working with records instead of plain text paths to the image, you have to use the ID of the record to get the actual image file.
Since I am not 100% sure, you should check if 12 is the ID of the sys_file_reference record or the sys_file record used for that particular image before using the usual < f:image> viewhelper either with or without "treatIdAsReference".
https://docs.typo3.org/typo3cms/ExtbaseGuide/Fluid/ViewHelper/Image.html
If you just need the path to the image and not an image tag you should go for < f:uri.image> instead.
https://docs.typo3.org/typo3cms/ExtbaseGuide/Fluid/ViewHelper/Uri/Image.html

This is how I did it some time ago, using the media field of tt_content instead of using flexform. This solution assumes that
a) you are using a "frontend provider" extension (EXT:yourext) that stores your TypoScript and Fluid Templates
b) EXT:yourext depends on EXT:gridelements
c) In this example, my gridelement object is called twocolumnscontainer
1) TS Constants: use EXT:yourext as alternative path for fluid templates, layouts, partials
styles.templates.templateRootPath = EXT:yourext/Resources/Private/Templates/ContentElements/
styles.templates.partialRootPath = EXT:yourext/Resources/Private/Partials/ContentElements/
styles.templates.layoutRootPath = EXT:yourext/Resources/Private/Layouts/ContentElements/
2) in TS Setup, define the template cObject for content grids
lib.gridelements.defaultGridSetup.cObject =< lib.contentElement
tt_content.gridelements_pi1.20.10.setup.twocolumnscontainer < lib.gridelements.defaultGridSetup
tt_content.gridelements_pi1.20.10.setup.twocolumnscontainer {
cObject.templateName = GridElementTwoColumns
cObject.dataProcessing {
10 = TYPO3\CMS\Frontend\DataProcessing\FilesProcessor
10 {
references.fieldName = media
as = backgroundimage
}
}
}
3) In TS Config:
tx_gridelements.setup.twocolumnscontainer {
title = Two columns element with background image
description = whatever
config{
colCount = 2
rowCount = 1
rows {
1 {
columns {
1 {
name = column 1
colPos = 100
}
2 {
name = column 2
colPos = 101
}
}
}
}
}
}
4) EXT:yourext/TCA/Overrides/tt_content_element_gridelement.php
<?php
defined('TYPO3_MODE') || die();
call_user_func(function()
{
/**
* Limit the number of images in "media" for gridelements contents
*/
$GLOBALS['TCA']['tt_content']['types']['gridelements_pi1']['columnsOverrides']['media']['config']['maxitems']=1;
});
5) Define the Fluid template (I removed the classes so you can use whatever you want, Bootstrap, Foundation...):
EXT:yourext/Resources/Private/Templates/ContentElements/GridElementTwoColumns.html
<f:layout name="Default"/>
<f:section name="Main">
<f:if condition="{backgroundimage.0}">
{f:uri.image(image:backgroundimage.0)}
</f:if>
<div class="">
<div class="">
{data.tx_gridelements_view_column_100-> f:format.raw()}
</div>
<div class="">
{data.tx_gridelements_view_column_101-> f:format.raw()}
</div>
</div>
</f:section>
I hope I have not forgotten important steps :)

This should work for you:
<f:uri.image src="{data.flexform_backgroundimage}" treatIdAsReference="1"/>

Related

How to deliver TYPO3 Fluid Form elements created outside template?

How can I deliver prepared fluid form elements using PHP and have them process in a fluid template?
Something like:
Controller:
public function indexAction(): void {
$html = '<div class="wrap">
<f:form.textfield name="email" value=""/>
<f:form.textfield name="token" value="a#b.com"/>
</div>';
$this->view->assign('elements', ['data' => $html]);
}
Index Template:
<f:form ...">
<div class="F">{elements.data -> f:format.raw()}</div>
</f:form>
Rendering Fluid is no iterating process and so your Fluid in a variable will not be rendered as Fluid.
If you want variants you could use partials which can be controlled by a variable
<f:if condition="{var1} == 'long'">
<f:then>
<render partial="longVersion" arguments="{_all}" />
</f:then>
<f:else>
<render partial="shortVersion" arguments="{_all}" />
</f:else>
</f:if>
you even can use the variabel to select the partial directly:
<f:render partial="Part_{var1}" arguments="{_all}" />
Another way would be to insert the rendered Fluid in to the variable.
in Typoscript this coul be like this:
10 = FLUIDTEMPLATE
10 {
template = outer
variables {
part1 = FLUIDTEMPLATE
part1 {
template = inner
variables {
:
}
}
:
}
}
or dynamically:
<f:cObject typoscriptObjectPath="lib.subtemplate">
lib.subtemplate = FLUIDTEMPLATE
lib.subtemplate {
template = inner
variables {
:
}
}

How to access Page's Resources files in Fluid Typo3

Page's Resources Tab
I have been trying to access these files but with no luck. Any help is appreciated.
If your system has EXT:vhs installed you can get this via vhs viewhelper like this,
{namespace v=FluidTYPO3\Vhs\ViewHelpers}
<v:page.resources.fal table="pages" field="media" uid="{page.uid}" as="images" slide="-1" >
<f:for each="{images}" as="image">
<f:image src="{image.url}" alt="{image.alternative} {image.name}" title="{image.title}" />
</f:for>
</v:page.resources.fal>
you can get more about this from here: https://github.com/FluidTYPO3/vhs/pull/395 and https://fluidtypo3.org/viewhelpers/vhs/2.3.3/Page/Resources/FalViewHelper.html#argument-slide
You can use typoscrpt solution as well,
lib.pageResources = FILES
lib.pageResources {
references {
table = pages
uid.data = uid
fieldName = media
}
renderObj = IMAGE
renderObj {
file {
import.data = file:current:uid
treatIdAsReference = 1
width = 150c
height = 150c
}
altText.data = file:current:alternative
titleText.data = file:current:title
}
maxItems = 3
}
Render this with:
<f:cObject typoscriptObjectPath="lib.pageResources" />
You can get more about this from here: https://riptutorial.com/typo3/example/21734/image-and-image-resource
Hope this helps you... #KeepCoding.. ;)
Regards
To access the Page Resources files / image in the TYPO3 Fluid, take this example:
<f:if condition="{files}">
<f:then>
<f:for each="{files}" as="image">
<f:uri.image image="{image}" />
</f:for>
</f:then>
</f:if>
all the Page Resources files / images find you in the "files". take the <f:debug>{_all}</f:debug>

TYPO3: localization condition, sys_language_uid in fluid-template

What I would like to achieve is that an image changes depending on what language is selected at that moment.
This is my HTML
<f:if condition="{TSFE:sys_language_uid} == 1">
<f:then>
<f:link.page pageUid="{settings.rootpid}" class="navbar-brand">
<img src="fileadmin/branding/brand/images/png/image1.png" alt="Logo {settings.brandname}" />
</f:link.page>
</f:then>
<f:else>
<f:link.page pageUid="{settings.rootpid}" class="navbar-brand">
<img src="fileadmin/branding/brand/images/png/image2.png" alt="Logo {settings.brandname}" />
</f:link.page>
</f:else>
</f:if>
And this is my TS
[globalVar = GP:L = 1]
config {
sys_language_uid = 1
language = nl
locale_all = nl_NL.UTF-8
htmlTag_setParams = lang="nl" dir="ltr" class="no-js"
}
[global]
[globalVar = GP:L = 2]
config {
sys_language_uid = 2
language = fr
locale_all = fr_FR.UTF-8
htmlTag_setParams = lang="fr" dir="ltr" class="no-js"
}
[global]
I tried a ton of different ways of writing this but can't seem to make it work hopefully somebody can help.
I assume that you are using your own distribution, or extend the functionality of some package ...
Try this in your constants.ts (so they are available in the BE constant editor) myext/Configuration/TypoScript/constants.ts :
myext.configuration {
logo {
src {
# cat=myext/general/05; type=string; label=English Logo
default = fileadmin/branding/brand/images/png/image0.png
# cat=myext/general/06; type=string; label=Dutch Logo
nl = fileadmin/branding/brand/images/png/image1.png
# cat=myext/general/07; type=string; label=French Logo
fr = fileadmin/branding/brand/images/png/image2.png
}
}
}
then this in your setup.ts myext/Configuration/TypoScript/setup.ts :
page = PAGE
page {
# Page Main template
10 = FLUIDTEMPLATE
10 {
variables {
# Logo
logoSrc = TEXT
logoSrc.value = {$myext.configuration.logo.src.default}
}
}
}
[globalVar = GP:L=1]
page.10.variables.logoSrc.value = {$myext.configuration.logo.src.nl}
[end]
[globalVar = GP:L=2]
page.10.variables.logoSrc.value = {$myext.configuration.logo.src.fr}
[end]
now you can simply use {logoSrc} in your fluidtemplate
...
<f:link.page pageUid="{settings.rootpid}" class="navbar-brand">
<img src="{logoSrc}" alt="Logo {settings.brandname}" />
</f:link.page>
...
Pass the pre-evaluated boolean to the template. Either from your controller (there you have access to the TSFE) or via TS to the FLUIDTEMPLATE object. It's not clear from the question where you are coming from. You should move the condition inline into the src, this way you don't duplicate the whole markup, but only switch the value.
Alternatively, you can pre-calculate the src value in the controller or TS and just pass it to the view.
You can get current languageUid using viewHelper something like below.
You ViewHelper file.
<?php
namespace MyVendor\ExtensionKey\ViewHelpers;
class GetLangUidViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper {
/**
* GetLangUid
*
**/
public function render() {
return $GLOBALS['TSFE']->sys_language_uid;
}
}
In your fluid template get current laguageUid like below.
{namespace L=MyVendor\ExtensionKey\ViewHelpers}
<f:if condition="{L:getLangUid()} == 1">
<f:then>
<f:link.page pageUid="{settings.rootpid}" class="navbar-brand">
<img src="fileadmin/branding/brand/images/png/image1.png" alt="Logo {settings.brandname}" />
</f:link.page>
</f:then>
<f:else>
<f:link.page pageUid="{settings.rootpid}" class="navbar-brand">
<img src="fileadmin/branding/brand/images/png/image2.png" alt="Logo {settings.brandname}" />
</f:link.page>
</f:else>
</f:if>

extbase action only called if i am logged in backend

When I am logged in Backend, the content of "Anzeigenverwaltung" is rendered. "Anzeigenverwaltung" is my extension that calls the "listAction", which works fine. Action is called, template for this action is rendered.
But if i logout from Backend then "Anzeigenverwaltung" is not being rendered.
The content "Test" is always being rendered.
It is a fresh TYPO3 8.7 installation.
Is there any security related configuration that does not allow to call the action without an BE session?
Here is some code of my extension:
// setup.txt
page = PAGE
page.10 = FLUIDTEMPLATE
page.10 {
templateName = myextension
templateRootPaths.0 = EXT:myextension/Resources/Private/Templates
variables {
content < styles.content.get
content.select.where = colPos = 0
}
}
plugin.tx_myextension {
persistence {
storagePid = 7,10
classes {
TYPO3\Myextension\Domain\Model\Location.newRecordStoragePid = 10
}
}
}
// myextension.html
<section>
<div class="container-fluid">
<div class="content">
<f:format.raw>{content}</f:format.raw>
</div>
</div>
</section>
// extbase controller
class PackageController extends \MyVendor\Myextension\Controller\AbstractController {
public function listAction() {
$packages = $this->packageRepository->findAll();
$this->view->assign('packages', $packages);
}
}
// listAction template
<f:for each="{packages}" as="package">
<f:link.action pageUid="{settings.single}" action="single" arguments="{package: package}">
</f:for>
Update:
// ext_tables.php
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addStaticFile($_EXTKEY, 'TS', 'MyExtension');
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPageTSConfig('RTE.default.preset = full');
$EXTDIRFULL = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath($_EXTKEY);
$EXTDIR = 'EXT:myextension/';
$LANG = 'LLL:EXT:myextension/Resources/Private/Language/locallang.xml' . ':';
$PID_DEFAULT = 10;
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin(
'MyVendor.' . $_EXTKEY,
'Package',
$LANG . 'admanager'
);
include_once $EXTDIRFULL . 'Configuration/TCA/package.php';
// FlexForm PackageController
$GLOBALS['TCA']['tt_content']['types']['list']['subtypes_addlist'][$_EXTKEY . '_package'] = 'pi_flexform';
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPiFlexFormValue($_EXTKEY . '_package', 'FILE:EXT:package/Flexform/package.xml');
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPlugin(array($LANG . 'admanager', $_EXTKEY . '_package'), 'list_type', $_EXTKEY);
// ext_localconf.php
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin(
'MyVendor.' . $_EXTKEY,
'Package',
array(
'Package' =>
'list,single'
)
);
// flexform
<T3DataStructure>
<sheets>
<general>
<ROOT>
<TCEforms>
<sheetTitle>Display type</sheetTitle>
</TCEforms>
<type>array</type>
<el>
<switchableControllerActions>
<TCEforms>
<label>Display</label>
<config>
<type>select</type>
<items type="array">
<numIndex index="1" type="array">
<numIndex index="0">LLL:EXT:myextension/Resources/Private/Language/locallang.xml:listview</numIndex>
<numIndex index="1">Package->list;Package->single;</numIndex>
</numIndex>
</items>
</config>
</TCEforms>
</switchableControllerActions>
</el>
</ROOT>
</general>
</sheets>
</T3DataStructure>

Can I also slide content with Fluid Powered TYPO3 (fed flux fluidcontent)

I try to slide content elements at my TYPO3 Backend (v6.2) with Fluid Powered TYPO3. So I don't have CSS_Styled_content included. http://wiki.typo3.org/Content_Slide Example:
10 < styles.content.getRight
10.slide = -1
Especially I'd like to slide my content from the colPos=0 'Slider' to the Pages below. Is this possible with FLUID / FluidTYPO3 (FLUX)?
<f:section name="Configuration">
<flux:form id="fluidpage" options="{icon: 'typo3conf/ext/my_extension/Resources/Public/Icons/Page/Standard.gif'}">
</flux:form>
<flux:grid>
<flux:grid.row>
<flux:grid.column colPos="0" name="Slider" colspan="2" />
</flux:grid.row>
<flux:grid.row>
<flux:grid.column colPos="1" name="Left" />
<flux:grid.column colPos="2" name="Right" />
</flux:grid.row>
</flux:grid>
</f:section>
I try it like this ... but that's wrong.
styles.content.getSlider.slide = -1
You can do it in just the same way it is done in css_styled_content internally, using a CONTENT object:
lib.content_not_cascading_without_default = CONTENT
lib.content_not_cascading_without_default {
table = tt_content
# This enables content sliding. For more possible values
# check the docs (linked above)
slide = -1
select {
# Use the correct column position here
andWhere = colPos = 1
orderBy = sorting
languageField = sys_language_uid
}
}
Alternatively, if you use fluid to render the template, you can also render the content using the v:content.render-ViewHelper from EXT:vhs:
<v:content.render column="1" slide="-1"/>