Создать массивы и объекты с жидкостями f: variable - PullRequest
0 голосов
/ 30 января 2019

Можно ли создать массив или объект с переменной f: в TYPO3 9.x?

Пример ниже не работает, поскольку он обрабатывает объект как строку.

<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:.Да, я знаю, я мог бы назначить этот объект, но это не мое намерение.

1 Ответ

0 голосов
/ 27 февраля 2019

Здесь у вас есть пример частичного из 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>
...