我正在使用TYPO3 8.7
和最新的扩展名gridelements
(8.2.3)。现在,我想在FLUIDTEMPLATE
中显示/渲染图像。-但我不知道如何?!?
这是我的TypoScript:
tt_content {
gridelements_pi1 = COA
gridelements_pi1 {
20 {
10 {
setup {
SectionColoured < lib.gridelements.defaultGridSetup
SectionColoured {
cObject = FLUIDTEMPLATE
cObject {
file = EXT:myext/.../SectionColoured.html
}
}
}
}
}
}
}
现在,我通过flexforms上传图像(例如,用于背景图像),
<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>
到目前为止有效。如何在FLUIDTEMPLATE中使用图像?调试器在12
上返回{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>
调试{data}
..谢谢您的帮助!
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)
答案 0 :(得分:1)
这很有趣。如果我尝试使用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>
我会收到错误消息You must either specify a string src or a File object.
现在我使用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>
一切正常.. vhs
扩展名的here's the view helper reference。感谢您的帮助!
答案 1 :(得分:0)
这是我前一段时间做的,使用media
的{{1}}字段而不是flexform。该解决方案假定
a)您正在使用“前端提供程序”扩展名(EXT:yourext)存储您的TypoScript和Fluid模板
b)EXT:yourext取决于EXT:gridelements
c)在此示例中,我的网格元素对象称为tt_content
1)TS常数:使用EXT:yourext作为流体模板,布局,零件的替代路径
twocolumnscontainer
2)在TS设置中,为内容网格定义模板cObject
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/
3)在TS Config中:
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
}
}
}
4)EXT:yourext / TCA / Overrides / tt_content_element_gridelement.php
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
}
}
}
}
}
}
5)定义Fluid模板(我删除了类,以便您可以使用所需的任何东西,Bootstrap,Foundation ...): EXT:yourext / Resources / Private / Templates / ContentElements / GridElementTwoColumns.html
<?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;
});
我希望我没有忘记重要的步骤:)
答案 2 :(得分:0)
由于FAL使用的是记录而不是图像的纯文本路径,因此必须使用记录的ID才能获取实际的图像文件。
由于我不确定100%,因此在使用带或不带“ treatIdAsReference”的常规
https://docs.typo3.org/typo3cms/ExtbaseGuide/Fluid/ViewHelper/Image.html
如果您只需要图像的路径而不是图像标签,则应使用
https://docs.typo3.org/typo3cms/ExtbaseGuide/Fluid/ViewHelper/Uri/Image.html
答案 3 :(得分:0)
这应该对您有用:
<f:uri.image src="{data.flexform_backgroundimage}" treatIdAsReference="1"/>