跳到内容

模板支持

编辑此页

启用模板插件

该 bundle 允许您管理额外的模板。要使用此功能,您需要启用 bundle 自带的 templates 插件。您可以在全局配置中定义它

1
2
3
4
5
6
# app/config/config.yml
fos_ck_editor:
    default_config: my_config
    configs:
        my_config:
            extraPlugins: "templates"

或者您可以在您的组件中定义它

1
2
3
4
5
$builder->add('field', 'ckeditor', [
    'config' => [
        'extraPlugins' => 'templates',
    ],
]);

配置您的模板

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# app/config/config.yml
fos_ck_editor:
    default_config: my_config
    configs:
        my_config:
            extraPlugins: "templates"
            templates:    "my_templates"
    templates:
        my_templates:
            imagesPath: "/bundles/mybundle/templates/images"
            templates:
                -
                    title:       "My Template"
                    image:       "image.jpg"
                    description: "My awesome template"
                    html:        "<p>Crazy template :)</p>"

或者您可以在您的组件中定义它们

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
$builder->add('field', 'ckeditor', [
    'config' => [
        'extraPlugins' => 'templates',
        'templates'    => 'my_template',
    ],
    'templates' => [
        'my_template' => [
            'imagesPath' => '/bundles/mybundle/templates/images',
            'templates'  => [
                [
                    'title'       => 'My Template',
                    'image'       => 'images.jpg',
                    'description' => 'My awesome template',
                    'html'        => '<p>Crazy template :)</p>',
                ],
                // ...
            ],
        ],
    ],
]);

使用专用模板

如果您喜欢在专用的 Twig 或 PHP 模板中定义您的 html,您可以将 html 节点替换为 template 节点,并提供您的模板路径。您可以选择性地使用 template_parameters 节点提供模板参数。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# app/config/config.yml
fos_ck_editor:
    default_config: my_config
    configs:
        my_config:
            extraPlugins: "templates"
            templates:    "my_templates"
    templates:
        my_templates:
            imagesPath: "/bundles/mybundle/templates/images"
            templates:
                -
                    title:       "My Template"
                    image:       "image.jpg"
                    description: "My awesome template"
                    template:    "AppBundle:CKEditor:template.html.twig"
                    template_parameters:
                        foo: bar

或者您可以在您的组件中定义它们

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
$builder->add('field', 'ckeditor', [
    'config' => [
        'extraPlugins' => 'templates',
        'templates'    => 'my_template',
    ],
    'templates' => [
        'my_template' => [
            'imagesPath' => '/bundles/mybundle/templates/images',
            'templates'  => [
                [
                    'title'               => 'My Template',
                    'image'               => 'images.jpg',
                    'description'         => 'My awesome template',
                    'template'            => 'AppBundle:CKEditor:template.html.twig',
                    'template_parameters' => ['foo' => 'bar'],
                ],
                // ...
            ],
        ],
    ],
]);
本作品,包括代码示例,根据 Creative Commons BY-SA 3.0 许可协议获得许可。
目录
    版本