append-javascript.rst 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. Append Custom Javascript
  2. ========================
  3. The bundle allows you to easily append custom javascript code into
  4. all CKEditor widgets by simply overriding the default templates. Here,
  5. we will configure CKEditor to not remove empty span via the DTD.
  6. Twig Template
  7. -------------
  8. The default Twig template is ``FOSCKEditorBundle:Form:ckeditor_widget.html.twig``.
  9. This one has some blocks you can override according to your needs.
  10. .. code-block:: twig
  11. {# app/Resources/views/Form/ckeditor_widget.html.twig #}
  12. {% extends 'FOSCKEditorBundle:Form:ckeditor_widget.html.twig' %}
  13. {% block ckeditor_widget_extra %}
  14. CKEDITOR.dtd.$removeEmpty['span'] = false;
  15. {% endblock %}
  16. Then, just need to register your template as a form resources in the
  17. configuration and it will override the default one:
  18. .. code-block:: yaml
  19. # app/config/config.yml
  20. twig:
  21. form_themes:
  22. - "::Form/ckeditor_widget.html.twig"
  23. PHP Template
  24. ------------
  25. The default PHP template is ``FOSCKEditorBundle:Form:ckeditor_widget.html.php``.
  26. This one has some slots you can override according to your needs.
  27. .. code-block:: php
  28. <!-- app/Resources/views/Form/ckeditor_widget.html.php -->
  29. <?php $view->extend('FOSCKEditorBundle:Form:ckeditor_widget.html.php') ?>
  30. <?php $view['slots']->start('ckeditor_widget_extra') ?>
  31. CKEDITOR.dtd.$removeEmpty['span'] = false;
  32. <?php $view['slots']->stop() ?>
  33. .. code-block:: yaml
  34. # app/config/config.yml
  35. framework:
  36. templating:
  37. form:
  38. resources:
  39. - "::Form"