1

我尝试使用 VHS(版本 2.4.0) RandomViewHelper 输出 1 个随机图像v:iterator.random

这是我的代码:

{namespace flux=FluidTYPO3\Flux\ViewHelpers}
{namespace v=FluidTYPO3\Vhs\ViewHelpers}

    <f:layout name="Content" />

    <f:section name="Configuration">
        <flux:form id="random-image" label="Random Image" options="{icon: 'Icons/Content/Example.gif', group: 'Joya'}">
            <flux:field.input name="classname" label="Classname" />
        </flux:form>

        <flux:form.section name="images" label="Images">
            <flux:form.object name="image" label="Image">
                <flux:field.file name="imagesrc" label="Image" allowed="png,jpg" maxItems="1" size="1" />

            </flux:form.object>
        </flux:form.section>

    </f:section>

    <f:section name="Preview">
        Random Image
    </f:section>

    <f:section name="Main">
        <div class="random-image">
        <v:iterator.random as="img" subject="{images}">
            {img.image.imagesrc}
        </v:iterator.random>

        </div>
    </f:section>

我添加了 3 张图像进行测试,但它总是输出相同的图像。 编辑:随机的输出被缓存。所以它在缓存被清除后输出另一个图像。

我可以只为这行代码禁用缓存吗?

https://fluidtypo3.org/viewhelpers/vhs/2.4.0/Iterator/RandomViewHelper.html

4

2 回答 2

1

解决方案是使用 VHS ViewHelperv:render.uncache并使用不应缓存的部分创建一个部分。它不是最好的解决方案,因为您需要一个额外的文件。但现在我能想到的唯一其他方法是使用一些 Typoscript,这也是我想要避免的。

于 2016-04-13T13:32:28.417 回答
0

另一种方法是通过ajax调用加载图像,这样你可以缓存页面,但不能缓存随机图像。

于 2016-04-13T13:17:20.833 回答