admin_templates.rst 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. ===========================
  2. Customising admin templates
  3. ===========================
  4. In your projects with Wagtail, you may wish to replace elements such as the Wagtail logo within the admin interface with your own branding. This can be done through Django's template inheritance mechanism.
  5. .. note::
  6. Using ``{% extends %}`` in this way on a template you're currently overriding is only supported in Django 1.9 and above. On Django 1.8, you will need to use `django-overextends <https://github.com/stephenmcd/django-overextends>`_ instead.
  7. You need to create a ``templates/wagtailadmin/`` folder within one of your apps - this may be an existing one, or a new one created for this purpose, for example, ``dashboard``. This app must be registered in ``INSTALLED_APPS`` before ``wagtail.wagtailadmin``:
  8. .. code-block:: python
  9. INSTALLED_APPS = (
  10. # ...
  11. 'dashboard',
  12. 'wagtail.wagtailcore',
  13. 'wagtail.wagtailadmin',
  14. # ...
  15. )
  16. .. _custom_branding:
  17. Custom branding
  18. ===============
  19. The template blocks that are available to customise the branding in the admin interface are as follows:
  20. ``branding_logo``
  21. -----------------
  22. To replace the default logo, create a template file ``dashboard/templates/wagtailadmin/base.html`` that overrides the block ``branding_logo``:
  23. .. code-block:: html+django
  24. {% extends "wagtailadmin/base.html" %}
  25. {% load staticfiles %}
  26. {% block branding_logo %}
  27. <img src="{% static 'images/custom-logo.svg' %}" alt="Custom Project" width="80" />
  28. {% endblock %}
  29. ``branding_favicon``
  30. --------------------
  31. To replace the favicon displayed when viewing admin pages, create a template file ``dashboard/templates/wagtailadmin/admin_base.html`` that overrides the block ``branding_favicon``:
  32. .. code-block:: html+django
  33. {% extends "wagtailadmin/admin_base.html" %}
  34. {% load staticfiles %}
  35. {% block branding_favicon %}
  36. <link rel="shortcut icon" href="{% static 'images/favicon.ico' %}" />
  37. {% endblock %}
  38. ``branding_login``
  39. ------------------
  40. To replace the login message, create a template file ``dashboard/templates/wagtailadmin/login.html`` that overrides the block ``branding_login``:
  41. .. code-block:: html+django
  42. {% extends "wagtailadmin/login.html" %}
  43. {% block branding_login %}Sign in to Frank's Site{% endblock %}
  44. ``branding_welcome``
  45. --------------------
  46. To replace the welcome message on the dashboard, create a template file ``dashboard/templates/wagtailadmin/home.html`` that overrides the block ``branding_welcome``:
  47. .. code-block:: html+django
  48. {% extends "wagtailadmin/home.html" %}
  49. {% block branding_welcome %}Welcome to Frank's Site{% endblock %}
  50. Specifying a site or page in the branding
  51. =========================================
  52. The admin interface has a number of variables available to the renderer context that can be used to customize the branding in the admin page. These can be useful for customizing the dashboard on a multitenanted Wagtail installation:
  53. ``root_page``
  54. -------------
  55. Returns the highest explorable page object for the currently logged in user. If the user has no explore rights, this will default to ``None``.
  56. ``root_site``
  57. -------------
  58. Returns the name on the site record for the above root page.
  59. ``site_name``
  60. -------------
  61. Returns the value of ``root_site``, unless it evaluates to ``None``. In that case, it will return the value of ``settings.WAGTAIL_SITE_NAME``.
  62. To use these variables, create a template file ``dashboard/templates/wagtailadmin/home.html``, just as if you were overriding one of the template blocks in the dashboard, and use them as you would any other Django template variable:
  63. .. code-block:: html+django
  64. {% extends "wagtailadmin/home.html" %}
  65. {% block branding_welcome %}Welcome to the Admin Homepage for {{ root_site }}{% endblock %}
  66. Extending the login form
  67. ========================
  68. To add extra controls to the login form, create a template file ``dashboard/templates/wagtailadmin/login.html``.
  69. ``above_login`` and ``below_login``
  70. -----------------------------------
  71. To add content above or below the login form, override these blocks:
  72. .. code-block:: html+django
  73. {% extends "wagtailadmin/login.html" %}
  74. {% block above_login %} If you are not Frank you should not be here! {% endblock %}
  75. ``fields``
  76. ----------
  77. To add extra fields to the login form, override the ``fields`` block. You will need to add ``{{ block.super }}`` somewhere in your block to include the username and password fields:
  78. .. code-block:: html+django
  79. {% extends "wagtailadmin/login.html" %}
  80. {% block fields %}
  81. {{ block.super }}
  82. <li class="full">
  83. <div class="field iconfield">
  84. Two factor auth token
  85. <div class="input icon-key">
  86. <input type="text" name="two-factor-auth">
  87. </div>
  88. </div>
  89. </li>
  90. {% endblock %}
  91. ``submit_buttons``
  92. ------------------
  93. To add extra buttons to the login form, override the ``submit_buttons`` block. You will need to add ``{{ block.super }}`` somewhere in your block to include the sign in button:
  94. .. code-block:: html+django
  95. {% extends "wagtailadmin/login.html" %}
  96. {% block submit_buttons %}
  97. {{ block.super }}
  98. <a href="{% url 'signup' %}"><button type="button" class="button" tabindex="4">{% trans 'Sign up' %}</button></a>
  99. {% endblock %}
  100. ``login_form``
  101. --------------
  102. To completely customise the login form, override the ``login_form`` block. This block wraps the whole contents of the ``<form>`` element:
  103. .. code-block:: html+django
  104. {% extends "wagtailadmin/login.html" %}
  105. {% block login_form %}
  106. <p>Some extra form content</p>
  107. {{ block.super }}
  108. {% endblock %}