README.rst 7.54 KB
Newer Older
David Baumgold committed
1 2 3 4 5 6 7 8 9 10
#####################
Comprehensive Theming
#####################


Comprehensive Theming lets you customize the appearance of your Open edX
installation.  You can override Sass and CSS settings, images, or entire HTML
templates.

Eventually, Comprehensive Theming will obsolete existing theming mechanisms,
11
but for now they co-exist peacefully. This document describes how to use
David Baumgold committed
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
Comprehensive Theming, and also the changes you'll need to make to keep other
theming mechanisms working.


Creating a theme
================

A theme is a directory of assets.  You can create this directory wherever you
like, it does not have to be inside the edx-platform directory.  The structure
within this directory mirrors the assets in the edx-platform repo itself.
Files you provide in your theme are used in place of the same-named files in
edx-platform.  Here's a sample::

    my-theme
    └── lms
        ├── static
        │   ├── images
        │   │   └── logo.png
        │   └── sass
        │       ├── _overrides.scss
        │       ├── lms-main-rtl.scss
        │       └── lms-main.scss
        └── templates
            ├── footer.html
            └── header.html

The top directory is named whatever you like.  This example uses "my-theme".
The files provided here override the files in edx-platform.  In this case, the
``my-theme/lms/static/sass/lms-main.scss`` file is used in place of the
41
``edx-platform/lms/static/sass/lms-main.scss`` file.
David Baumgold committed
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68


Images
------

Images can be substituted simply by placing the new image at the right place
in the theme directory.  In our example above, the lms/static/images/logo.png
image is overridden.


Sass/CSS
--------

Most CSS styling in Open edX is done with Sass files compiled to CSS.  You can
override individual settings by creating a new Sass file that uses the existing
file, and overrides the few settings you want.

For example, to change the fonts used throughout the site, you can create an
``lms/static/sass/_overrides.scss`` file with the change you want::

    $sans-serif: 'Helvetica';

The variables that can currently be overridden are defined in
``lms/static/sass/base/_variables.scss``.

**Note:** We are currently in the middle of a re-engineering of the Sass
variables.  They will change in the future.  If you are interested, you can see
69
the new development in the `edX Pattern Library`_.
David Baumgold committed
70

71
.. _edX Pattern Library: http://ux.edx.org/
David Baumgold committed
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92

Then create ``lms/static/sass/lms-main.scss`` to use those overrides, and also
the rest of the definitions from the original file::

    // Our overrides for settings we want to change.
    @import 'overrides';

    // Import the original styles from edx-platform.
    @import 'lms/static/sass/lms-main';

Do this for each .scss file your site needs.


HTML Templates
--------------

You can make changes to HTML templates by copying them to your theme directory
in the appropriate place, and making the changes you need.  Keep in mind that
in the future if you upgrade the Open edX code, you may have to update the
copied template in your theme also.

93 94 95 96 97 98 99 100 101
Template Names
==============

Here are the list of template names that you *should* use in your comprehensive
theme (so far):

* ``header.html``
* ``footer.html``

David Baumgold committed
102 103 104
Installing your theme
---------------------

105 106
To use your theme, you need to add a configuration value pointing to your theme
directory. There are two ways to do this.
David Baumgold committed
107

108
#.  If you usually edit server-vars.yml:
David Baumgold committed
109

110 111
    #.  As the vagrant user, edit (or create)
        /edx/app/edx_ansible/server-vars.yml to add the
112
        ``edxapp_comprehensive_theme_dir`` value::
David Baumgold committed
113

114
            edxapp_comprehensive_theme_dir: '/full/path/to/my-theme'
David Baumgold committed
115

116
    #.  Run the update script::
David Baumgold committed
117

118 119 120 121
            $ sudo /edx/bin/update configuration master
            $ sudo /edx/bin/update edx-platform HEAD

#.  Otherwise, edit the /edx/app/edxapp/lms.env.json file to add the
122
    ``COMPREHENSIVE_THEME_DIRS`` value::
123

124
        "COMPREHENSIVE_THEME_DIRS": ["/full/path/to/my-theme"],
125 126

Restart your site.  Your changes should now be visible.
David Baumgold committed
127 128


129 130 131 132 133
Comprehensive Theming
=====================
* The ``PROFILE_IMAGE_DEFAULT_FILENAME`` Django setting is now ignored.


David Baumgold committed
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
"Stanford" theming
==================

If you want to continue using the "Stanford" theming system, there are a few
changes you'll need to make.

Create the following new files in the ``sass`` directory of your theme:

* lms-main.scss
* lms-main-rtl.scss
* lms-course.scss
* lms-course-rtl.scss
* lms-footer.scss
* lms-footer-rtl.scss

The contents of each of these files will be very similar. Here's what
``lms-main.scss`` should look like::

    $static-path: '../../../..';
    @import 'lms/static/sass/lms-main';
    @import '_default';

Each file should set the ``$static-path`` variable to a relative path that
points to the ``lms/static`` directory inside of ``edx-platform``. Then,
it should ``@import`` the sass file under ``lms/static/sass`` that matches
its name: ``lms-footer.scss`` should import ``lms/static/sass/lms-footer``,
for example. Finally, the file should import the ``_default`` name, which
refers to the ``_default.scss`` Sass file that should already exist in your
Stanford theme directory.

If your theme uses a different name than "default", you'll need to use that
name in the ``@import`` line.

Run the ``update_assets`` command to recompile the theme::

    $ paver update_assets lms --settings=aws
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194

Microsites
==========

If you want to continue using the "Microsites" theming system, there are a few
changes you'll need to make. A few templates have been renamed, or folded into
other templates:

* ``header_extra.html`` has been renamed to ``head-extra.html``. This file
  was always inserted into the ``<head>`` element of the page, rather than
  the header of the ``<body>`` element, so this change makes the name more
  accurate.

* ``google_analytics.html`` has been removed. The contents of this template
  can and should be added to the ``head-extra.html`` template.

* ``google_tag_manager.html`` has been renamed to ``body-initial.html``.

In addition, there are some other changes you'll need to make:

* The ``google_analytics_file`` config value is now ignored. If your Open edX
  installation has a Google Analytics account ID set, the Google Analytics
  JavaScript will be included automatically on your site using that account ID.
  You can set this account ID either using the "GOOGLE_ANALYTICS_ACCOUNT" value
  in the Django settings, or by setting the newly-added "GOOGLE_ANALYTICS_ACCOUNT"
195
  config value in your site configuration.
196 197

* If you don't want the Google Analytics JavaScript to be output at all in your
198
  site, set the "GOOGLE_ANALYTICS_ACCOUNT" config value to the empty string.
199 200 201 202 203 204
  If you want to customize the way that Google Analytics is loaded, set the
  "GOOGLE_ANALYTICS_ACCOUNT" config value to the empty string, and then load
  Google Analytics yourself (with whatever customizations you want) in your
  ``head-extra.html`` template.

* The ``css_overrides_file`` config value is now ignored. To add a CSS override
205
  file to your site configuration, create a ``head-extra.html`` template with the
206 207 208 209 210
  following content:

  .. code-block:: mako

    <%namespace name='static' file='../../static_content.html'/>
211
    <% style_overrides_file = static.get_value('css_overrides_file') %>
212 213 214 215 216 217 218 219

    % if style_overrides_file:
      <link rel="stylesheet" type="text/css" href="${static.url(style_overrides_file)}" />
    % endif

  If you already have a ``head-extra.html`` template, you can modify it to
  output this ``<link rel="stylesheet">`` tag, in addition to whatever else you
  already have in that template.