template.rst 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. Template support
  2. ================
  3. Enable the Templates Plugin
  4. ---------------------------
  5. The bundle offers you the ability to manage extra templates. To use this
  6. feature, you need to enable the ``templates`` plugins shipped with the bundle.
  7. You can define it globally in your configuration:
  8. .. code-block:: yaml
  9. # app/config/config.yml
  10. fos_ck_editor:
  11. default_config: my_config
  12. configs:
  13. my_config:
  14. extraPlugins: "templates"
  15. Or you can define it in your widget:
  16. .. code-block:: php
  17. $builder->add('field', 'ckeditor', array(
  18. 'config' => array(
  19. 'extraPlugins' => 'templates',
  20. ),
  21. ));
  22. Configure your templates
  23. ------------------------
  24. .. code-block:: yaml
  25. # app/config/config.yml
  26. fos_ck_editor:
  27. default_config: my_config
  28. configs:
  29. my_config:
  30. extraPlugins: "templates"
  31. templates: "my_templates"
  32. templates:
  33. my_templates:
  34. imagesPath: "/bundles/mybundle/templates/images"
  35. templates:
  36. -
  37. title: "My Template"
  38. image: "image.jpg"
  39. description: "My awesome template"
  40. html: "<p>Crazy template :)</p>"
  41. Or you can define them in your widget:
  42. .. code-block:: php
  43. $builder->add('field', 'ckeditor', array(
  44. 'config' => array(
  45. 'extraPlugins' => 'templates',
  46. 'templates' => 'my_template',
  47. ),
  48. 'templates' => array(
  49. 'my_template' => array(
  50. 'imagesPath' => '/bundles/mybundle/templates/images',
  51. 'templates' => array(
  52. array(
  53. 'title' => 'My Template',
  54. 'image' => 'images.jpg',
  55. 'description' => 'My awesome template',
  56. 'html' => '<p>Crazy template :)</p>',
  57. ),
  58. // ...
  59. ),
  60. ),
  61. ),
  62. ));
  63. Use a dedicated template
  64. ------------------------
  65. If you prefer define your html in a dedicated Twig or PHP template, you can
  66. replace the ``html`` node by the ``template`` one and provide the path of your
  67. template. You can optionally provide template parameters with the
  68. ``template_parameters`` node.
  69. .. code-block:: yaml
  70. # app/config/config.yml
  71. fos_ck_editor:
  72. default_config: my_config
  73. configs:
  74. my_config:
  75. extraPlugins: "templates"
  76. templates: "my_templates"
  77. templates:
  78. my_templates:
  79. imagesPath: "/bundles/mybundle/templates/images"
  80. templates:
  81. -
  82. title: "My Template"
  83. image: "image.jpg"
  84. description: "My awesome template"
  85. template: "AppBundle:CKEditor:template.html.twig"
  86. template_parameters:
  87. foo: bar
  88. Or you can define them in your widget:
  89. .. code-block:: php
  90. $builder->add('field', 'ckeditor', array(
  91. 'config' => array(
  92. 'extraPlugins' => 'templates',
  93. 'templates' => 'my_template',
  94. ),
  95. 'templates' => array(
  96. 'my_template' => array(
  97. 'imagesPath' => '/bundles/mybundle/templates/images',
  98. 'templates' => array(
  99. array(
  100. 'title' => 'My Template',
  101. 'image' => 'images.jpg',
  102. 'description' => 'My awesome template',
  103. 'template' => 'AppBundle:CKEditor:template.html.twig',
  104. 'template_parameters' => array('foo' => 'bar'),
  105. ),
  106. // ...
  107. ),
  108. ),
  109. ),
  110. ));