loading.rst 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. Manage CKEditor loading
  2. =======================
  3. By default, in order to prototype your form really fast, the bundle loads
  4. the CKEditor library each time you declare a CKEditor form. Basically, it
  5. means that if you have three CKEditor fields in your form, then, there will
  6. be three CKEditor library loadings.
  7. Load CKEditor manually
  8. ----------------------
  9. If you want to control the CKEditor loading, you can configure the bundle to
  10. not load the library at all and let you the control of it. To disable the
  11. CKEditor library loading, you can do it globally in your configuration:
  12. .. code-block:: yaml
  13. # app/config/config.yml
  14. fos_ck_editor:
  15. autoload: false
  16. Or you can disable it in your widget:
  17. .. code-block:: php
  18. $builder->add('field', 'ckeditor', array('autoload' => false));
  19. .. note::
  20. If you use this approach, be aware CKEditor must be loaded before any fields
  21. have been rendered, so we recommend you to register it in the ``<head>`` of
  22. your page.
  23. Load CKEditor asynchronously
  24. ----------------------------
  25. If you want to load CKEditor at the bottom of your page, the best way is to still
  26. disable the CKEditor loading (in order to let you load CKEditor at the bottom of
  27. the page only one time) but also to configure the bundle to render the javascript
  28. latter with a dedicated function shipped in a third party bundle named
  29. IvoryFormExtraBundle_.
  30. So, first you need configure the bundle. You can do it globally in your
  31. configuration:
  32. .. code-block:: yaml
  33. # app/config/config.yml
  34. fos_ck_editor:
  35. autoload: false
  36. async: true
  37. Or you can configure it in your widget:
  38. .. code-block:: php
  39. $builder->add('field', 'ckeditor', array(
  40. 'autoload' => false,
  41. 'async' => true,
  42. ));
  43. Then, install the third party bundles as explained in its
  44. `documentation <https://github.com/egeloen/IvoryFormExtraBundle/blob/master/Resources/doc/installation.md>`_.
  45. Finally, in your Twig template, you can render the form javascript with:
  46. .. code-block:: twig
  47. {{ form_javascript(form) }}
  48. Or if you use the PHP templating engine:
  49. .. code-block:: php
  50. <?php echo $view['ivory_form_extra']->javascript($form) ?>
  51. .. note::
  52. If you use this approach, be aware CKEditor must be loaded before you render the
  53. form javascript.
  54. .. _`IvoryFormExtraBundle`: https://github.com/egeloen/IvoryFormExtraBundle