You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

TYPO3 widget.paginate生成无效下一页URL问题求助

TYPO3 Fluid Widget.Paginate生成无效URL导致PageNotFoundException(错误#1518472189)

问题描述

我正在开发一款读取JSON文件并展示图片的TYPO3扩展,图片展示功能正常,但在为500+张图片实现分页时遇到异常。使用Fluid的widget.paginate组件,点击「下一页」链接会生成无效URL:

http://localhost/work/index.php?id=7&tx_llgcinfinitescroll_message%5B%40widget_0%5D%5BcurrentPage%5D=2

触发TYPO3错误#1518472189 TYPO3\CMS\Core\Error\Http\PageNotFoundException。

我的Fluid代码如下:

<f:widget.paginate objects="{imageData}" as="paginatedImages" configuration="{itemsPerPage: 24, insertAbove: 1, insertBelow: 0}">
    <f:for each="{paginatedImages}" as="image" key="i">
        <!-- Assigning Variables -->
        <f:variable name="thumbnail" value="{image.imageData.thumbnail}"/>
        <f:variable name="fullSizeImage" value="{image.imageData.fullSizeImage}"/>
        <f:variable name="imageHeight" value="{image.imageData.imageHeight}"/>
        <f:variable name="label" value="{image.imageData.label}"/>
        <f:variable name="welshLabel" value="{image.imageData.welshLabel}"/>
        <f:variable name="description" value="{image.imageData.description}"/>
        <f:variable name="welshDescription" value="{image.imageData.welshDescription}"/>
        
        <!-- Displaying Images -->
        <div class="grid__item">
            <div class="hovereffect">
                <a href="{fullSizeImage}">
                    <img src="{thumbnail}" itemprop="thumbnail" alt="{label}">
                </a>
            </div>
        </div>
        <f:debug>{_all}</f:debug>
    </f:for>
</f:widget.paginate>

问题分析

这个问题的核心是URL中的&amp;没有被正确解析为&,导致TYPO3无法识别分页组件的查询参数(tx_llgcinfinitescroll_message[...]),进而抛出页面不存在的错误。常见触发原因包括:

  • 模板中的分页组件被意外包裹在HTML转义标签中,导致链接被二次转义
  • TYPO3全局配置开启了强制HTML转义,影响了widget链接的生成
  • 自定义扩展的控制器没有正确处理widget的请求逻辑

解决方案

我之前遇到过类似的情况,以下几个步骤可以帮你排查解决:

1. 检查模板是否存在过度转义

首先确认f:widget.paginate没有被包裹在f:format.htmlentities这类会转义HTML的标签中。如果有类似下面的错误写法,一定要移除外层的转义标签:

<!-- 错误示例:会转义widget生成的链接 -->
<f:format.htmlentities>
    <f:widget.paginate ...>...</f:widget.paginate>
</f:format.htmlentities>

2. 关闭不必要的HTML转义

在你的扩展setup.typoscript中添加配置,关闭Fluid模板的强制输出转义:

lib.fluidContent {
    templateRootPaths.10 = EXT:llgcinfinitescroll/Resources/Private/Templates/
    partialRootPaths.10 = EXT:llgcinfinitescroll/Resources/Private/Partials/
    layoutRootPaths.10 = EXT:llgcinfinitescroll/Resources/Private/Layouts/
    variables {
        settings {
            fluid {
                escapeOutput = 0
            }
        }
    }
}

如果你不想全局关闭转义,也可以给分页组件单独添加f:format.raw,确保链接输出为原始HTML:

<f:format.raw>
    <f:widget.paginate objects="{imageData}" as="paginatedImages" configuration="{itemsPerPage: 24, insertAbove: 1, insertBelow: 0}">
        <!-- 你的循环内容 -->
    </f:widget.paginate>
</f:format.raw>

3. 验证控制器和插件配置

确保你的自定义控制器继承了TYPO3\CMS\Fluid\Core\Widget\AbstractWidgetController,并且插件在ext_localconf.php中正确注册了允许前端请求的动作:

\TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin(
    'YourVendor.LlgcInfinitescroll',
    'Message',
    [
        'YourController' => 'list',
    ],
    // 允许前端请求(包括widget分页)
    [
        'YourController' => 'list',
    ]
);

4. 清理TYPO3缓存

修改配置或模板后,一定要彻底清理TYPO3的所有缓存(页面缓存、配置缓存、Fluid模板缓存),否则修改可能不会生效。可以通过后台的「清除缓存」按钮,或者使用命令行:

typo3 cache:flush

内容的提问来源于stack exchange,提问作者Mortgage1

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.14 07:56:11