page_editing_interface.rst 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. Customising the page editing interface
  2. ======================================
  3. .. _customising_the_tabbed_interface:
  4. Customising the tabbed interface
  5. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  6. .. versionadded:: 1.0
  7. As standard, Wagtail organises panels into three tabs: 'Content', 'Promote' and 'Settings'. Depending on the requirements of your site, you may wish to customise this for specific page types - for example, adding an additional tab for sidebar content. This can be done by specifying an ``edit_handler`` property on the page model. For example:
  8. .. code-block:: python
  9. from wagtail.wagtailadmin.edit_handlers import TabbedInterface, ObjectList
  10. class BlogPage(Page):
  11. # field definitions omitted
  12. content_panels = [
  13. FieldPanel('title', classname="full title"),
  14. FieldPanel('date'),
  15. FieldPanel('body', classname="full"),
  16. ]
  17. sidebar_content_panels = [
  18. SnippetChooserPanel('advert', Advert),
  19. InlinePanel('related_links', label="Related links"),
  20. ]
  21. edit_handler = TabbedInterface([
  22. ObjectList(content_panels, heading='Content'),
  23. ObjectList(sidebar_content_panels, heading='Sidebar content'),
  24. ObjectList(Page.promote_panels, heading='Promote'),
  25. ObjectList(Page.settings_panels, heading='Settings', classname="settings"),
  26. ])
  27. Rich Text (HTML)
  28. ~~~~~~~~~~~~~~~~
  29. Wagtail provides a general-purpose WYSIWYG editor for creating rich text content (HTML) and embedding media such as images, video, and documents. To include this in your models, use the :class:`~wagtail.wagtailcore.fields.RichTextField` function when defining a model field:
  30. .. code-block:: python
  31. from wagtail.wagtailcore.fields import RichTextField
  32. from wagtail.wagtailadmin.edit_handlers import FieldPanel
  33. class BookPage(Page):
  34. book_text = RichTextField()
  35. content_panels = Page.content_panels + [
  36. FieldPanel('body', classname="full"),
  37. ]
  38. :class:`~wagtail.wagtailcore.fields.RichTextField` inherits from Django's basic ``TextField`` field, so you can pass any field parameters into :class:`~wagtail.wagtailcore.fields.RichTextField` as if using a normal Django field. This field does not need a special panel and can be defined with ``FieldPanel``.
  39. However, template output from :class:`~wagtail.wagtailcore.fields.RichTextField` is special and need to be filtered to preserve embedded content. See :ref:`rich-text-filter`.
  40. If you're interested in extending the capabilities of the Wagtail WYSIWYG editor (``hallo.js``), See :ref:`extending_wysiwyg`.
  41. .. _extending_wysiwyg:
  42. Extending the WYSIWYG Editor (``hallo.js``)
  43. -------------------------------------------
  44. To inject JavaScript into the Wagtail page editor, see the :ref:`insert_editor_js <insert_editor_js>` hook. Once you have the hook in place and your ``hallo.js`` plugin loads into the Wagtail page editor, use the following JavaScript to register the plugin with ``hallo.js``.
  45. .. code-block:: javascript
  46. registerHalloPlugin(name, opts);
  47. ``hallo.js`` plugin names are prefixed with the ``"IKS."`` namespace, but the ``name`` you pass into ``registerHalloPlugin()`` should be without the prefix. ``opts`` is an object passed into the plugin.
  48. For information on developing custom ``hallo.js`` plugins, see the project's page: https://github.com/bergie/hallo
  49. Image Formats in the Rich Text Editor
  50. -------------------------------------
  51. On loading, Wagtail will search for any app with the file ``image_formats.py`` and execute the contents. This provides a way to customise the formatting options shown to the editor when inserting images in the :class:`~wagtail.wagtailcore.fields.RichTextField` editor.
  52. As an example, add a "thumbnail" format:
  53. .. code-block:: python
  54. # image_formats.py
  55. from wagtail.wagtailimages.formats import Format, register_image_format
  56. register_image_format(Format('thumbnail', 'Thumbnail', 'richtext-image thumbnail', 'max-120x120'))
  57. To begin, import the the ``Format`` class, ``register_image_format`` function, and optionally ``unregister_image_format`` function. To register a new ``Format``, call the ``register_image_format`` with the ``Format`` object as the argument. The ``Format`` class takes the following constructor arguments:
  58. ``name``
  59. The unique key used to identify the format. To unregister this format, call ``unregister_image_format`` with this string as the only argument.
  60. ``label``
  61. The label used in the chooser form when inserting the image into the :class:`~wagtail.wagtailcore.fields.RichTextField`.
  62. ``classnames``
  63. The string to assign to the ``class`` attribute of the generated ``<img>`` tag.
  64. ``filter_spec``
  65. The string specification to create the image rendition. For more, see the :ref:`image_tag`.
  66. To unregister, call ``unregister_image_format`` with the string of the ``name`` of the ``Format`` as the only argument.