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

如何在Sulu CMS首页Fixture中配置smart_content字段?

Sulu Fixture配置smart_content类型属性的解决方案

问题场景

在Sulu应用中创建首页Fixture时,自定义的service_slider块包含services(类型为smart_content,provider为pages)属性,后台手动选择service页面功能正常,但通过Fixture绑定数据时,services数组始终为空,尝试传入PageDocument对象或页面UUID均无效。

解决方案

Sulu的smart_content属性需要特定的数组结构来绑定数据,而非直接传入文档对象或单个UUID。需按照以下步骤配置:

1. 确保service页面已创建并持久化

首先在Fixture中创建所需的service页面,获取其UUID并完成持久化:

// 创建service页面示例
$servicePage1 = $this->createPage(
    'Service 1',
    'service', // 对应你的service页面类型
    'en'
);
$servicePage2 = $this->createPage(
    'Service 2',
    'service',
    'en'
);

// 持久化service页面
$this->documentManager->persist($servicePage1);
$this->documentManager->persist($servicePage2);
$this->documentManager->flush();

2. 按照smart_content结构绑定数据

在首页的结构绑定中,services字段需传入包含provider和ids的数组:

$homeDocument->getStructure()->bind([
    // 其他首页字段...
    'blocks' => [
        [
            'type' => 'service_slider',
            'title_text' => 'Lorem ipsum',
            'services' => [
                'provider' => 'pages', // 对应XML配置中的provider值
                'ids' => [
                    $servicePage1->getUuid(),
                    $servicePage2->getUuid()
                ],
                // 可选:如需限制显示数量可添加limit参数
                // 'limit' => 3
            ]
        ]
    ]
]);

// 持久化首页文档
$this->documentManager->persist($homeDocument);
$this->documentManager->flush();

关键说明

  • smart_content属性内部存储的是包含资源提供者和所选资源ID的结构化数据,直接传入文档对象或UUID无法被Sulu正确解析。
  • 注意blocks字段是数组类型,每个块元素需包裹在子数组中(即使只有一个块),否则无法正确识别块结构。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.14 18:28:25