Skip to content

Template support

Edit this page

Enable the Templates Plugin

The bundle offers you the ability to manage extra templates. To use this feature, you need to enable the templates plugins shipped with the bundle. You can define it globally in your configuration:

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

Or you can define it in your widget:

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

Configure your 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>"

Or you can define them in your widget:

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

Use a dedicated template

If you prefer define your html in a dedicated Twig or PHP template, you can replace the html node by the template one and provide the path of your template. You can optionally provide template parameters with the template_parameters node.

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

Or you can define them in your widget:

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', array(
    'config' => array(
        'extraPlugins' => 'templates',
        'templates'    => 'my_template',
    ),
    'templates' => array(
        'my_template' => array(
            'imagesPath' => '/bundles/mybundle/templates/images',
            'templates'  => array(
                array(
                    'title'               => 'My Template',
                    'image'               => 'images.jpg',
                    'description'         => 'My awesome template',
                    'template'            => 'AppBundle:CKEditor:template.html.twig',
                    'template_parameters' => array('foo' => 'bar'),
                ),
                // ...
            ),
        ),
    ),
));
This work, including the code samples, is licensed under a Creative Commons BY-SA 3.0 license.
TOC
    Version