使用fluid f:variable创建数组和对象

问题描述 投票:0回答:1

是否可以在TYPO3 9.x中使用f:变量创建数组或对象?

下面的示例不起作用,因为它将对象视为字符串。

<f:variable name="person">{firstname:'Max', lastname:'Mustermann'}</f:variable>

更新:此示例正在运行:

<f:variable name="person" value="{firstname:'Max', lastname:'Mustermann'}" />

为什么标记语法处理方式不同?

有趣的是,你可以在流体中'构建'数组并将它们作为参数传递给部分数据。

例:

<f:render partial="Components/ImageGallery" section="ImageGallery" arguments="{
  imageGallery: {
    0:{imageurl:'https://www.placehold.it/640x480',imagealt:'First Image', },
    1:{imageurl:'https://www.placehold.it/640x480',imagealt:'Second Alt'}
  }
}" />

如果有可能在流体中使用f:variable构建此对象,那将会很棒。是的我知道,我可以分配这个对象,但这不是我的意图。

typo3 fluid typo3-9.x
1个回答
0
投票

这里有一个来自https://github.com/Startpiloten/startpilot的部分示例

<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" data-namespace-typo3-fluid="true">

<f:if condition="{file}">
    <f:if condition="{breakpoints}">
        <f:else>
            <f:variable name="breakpoints" value="{settings.breakpoints}" />
        </f:else>
    </f:if>
    <f:link.typolink parameter="{file.link}" class="picturelink">
        <picture>
            <f:for each="{breakpoints}" as="breakpoint" iteration="i_breakpoints">
                <f:if condition="{i_breakpoints.isLast}">
                    <f:else>
                        <source srcset="{f:uri.image(image: file, maxWidth: breakpoint.maxWidth, cropVariant: breakpoint.cropVariant)}" media="({breakpoint.media}: {breakpoint.size}px)">
                    </f:else>
                    <f:then>
                        <source srcset="{f:uri.image(image: file, maxWidth: breakpoint.maxWidth, cropVariant: breakpoint.cropVariant)}" media="({breakpoint.media}: {breakpoint.size}px)">
                        <img class="img-fluid" src="{f:uri.image(image: file, maxWidth: breakpoint.maxWidth, cropVariant: breakpoint.cropVariant)}" alt="{file.alternative}" title="{file.title}">
                    </f:then>
                </f:if>
            </f:for>
        </picture>
    </f:link.typolink>
</f:if>

<f:comment>

    <!---Render Image with custom sizes from TS settings--->
    <f:render partial="ImageRender" arguments="{file:file, breakpoints:settings.breakpoints}" />

    <!---Render Image with custom sizes -- START --->
    <f:variable name="breakpoints" value="{
                            0:{media:'max-width', size:375, maxWidth:375, cropVariant:'mobile'},
                            1:{media:'max-width', size:480, maxWidth:480, cropVariant:'mobile'},
                            2:{media:'max-width', size:767, maxWidth:767, cropVariant:'tablet'},
                            3:{media:'max-width', size:991, maxWidth:991, cropVariant:'tablet'},
                            4:{media:'max-width', size:1279, maxWidth:1279, cropVariant:'default'},
                            5:{media:'max-width', size:1479, maxWidth:1479, cropVariant:'default'},
                            6:{media:'min-width', size:1480, maxWidth:2000, cropVariant:'default'}
                        }"/>

    <f:render partial="ImageRender" arguments="{file:image, breakpoints:breakpoints}" />
    <!---Render Image with custom sizes -- END --->

    <!---Render Image with default sizes -- START --->
    <f:render partial="ImageRender" arguments="{file:image}" />

</f:comment>

</html>
© www.soinside.com 2019 - 2024. All rights reserved.