123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- .. _customizing_templates:
- Customizing Templates & CSS
- ===========================
- Overview
- ---------
- Wagtail CRX is an extension of Wagtail. You can further customize your site by overriding the
- built-in templates to suit your needs. For this tutorial, we will assume that you have basic knowledge
- of the Django templating system. You can read more about it by visiting
- `Django template language <https://docs.djangoproject.com/en/stable/ref/templates/language/>`_.
- The templating language uses a series of ``{% %}`` to pull in content from your page models (found in
- the ``models.py`` file) and add minimal logic to the page. This allows it to render the page after content
- is added in the CMS and allows you to create multiple pages with the same layout. At the top of the page,
- you also want to make sure to either specify that you are
- however, you can see its contents
- by visiting the Wagtail CRX source code here: `navbar.html <https://github.com/coderedcorp/coderedcms/blob/main/coderedcms/templates/coderedcms/snippets/navbar.html>`_.
- Let’s say that you want to have a 2-tiered navbar with the logo on the top tier and the menu items on the
- second tier. The default navbar does not have that as an option, so you will want to override this template.
- Look at your folder structure for your project. By default, your project starts with a "website" folder (also known as a directory).
- In that directory there will be this path to base.html `templates/coderedcms/pages/base.html.`. This file is here for your convenience,
- you can add imports (like a google font) and it will override the default ``coderedcms`` base.html template. In the `website/templates/coderedcms` folder
- you are able override other ``coderedcms`` templates. To do this, the file structure and name must match the default templates.
- The `source code for built-in templates can be found on GitHub <https://github.com/coderedcorp/coderedcms/blob/main/coderedcms/templates/coderedcms/>`_.
- Many of your custom templates will go into your ``website`` folder because they are not overriding the
- default templates in the CMS but either extending them or creating completely new ones specific to
- your site.
- .. note::
- Adding templates to the ``coderedcms`` templates folder does not change the default templates
- throughout all of Wagtail CRX but does override those specific templates for your website app.
- Your ``website`` folder currently only has a folder for ``coderedcms`` in the ``templates`` folder.
- You can add a new ``website`` folder in ``templates`` (because we will use it in another tutorial),
- but for now, you will want to add a ``snippets`` folder inside the ``templates\coderedcms`` folder
- so that your folder structure looks something like this:
- .. figure:: img/A01/advanced_folder_structure1.png
- :alt: Our folder structure for templates.
- Our folder structure for templates within our website app.
- The folder structure needs to be the same as the default folder structure in the CMS if you want to
- override the navbar template. Now you should have ``templates\coderedcms\snippets``. Navigate to
- the ``snippets`` folder and create a ``navbar.html`` file inside of that folder. With your server running and the newly created file navbar.html file in place,
- look at your website. The navbar should be gone. The empty file is now overriding the default template.
- }
- .. figure:: img/A01/css_demo.jpg
- :alt: screen shot of custom.css
- A screen shot of custom.css with the above code added. (screen shot in VS code)
|