Skip to content

Commit f157f11

Browse files
committed
add to doc
1 parent d2d6289 commit f157f11

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

docs/html-templating.rst

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
.. _html-templating:
2+
3+
HTML Templating
4+
===============
5+
6+
pycsw uses `Jinja`_ as its templating engine to render HTML and `Flask`_ to provide route paths of the API that returns HTTP responses. For complete details on how to use these modules, refer to the `Jinja documentation`_ and the `Flask documentation`_.
7+
8+
The default pycsw configuration has ``server.templates`` commented out and defaults to the pycsw ``pycsw/templates`` and ``pycsw/static`` folder. To point to a different set of template configuration, you can edit your configuration as follows:
9+
10+
.. code-block:: yaml
11+
12+
server:
13+
templates:
14+
path: /path/to/jinja2/templates/folder # jinja2 template HTML files
15+
static: /path/to/static/folder # css, js, images and other static files referenced by the template
16+
17+
**Note:** the URL path to your static folder will always be ``/static`` in your deployed web instance of pycsw.
18+
19+
Your templates folder should mimic the same file names and structure of the default pycsw templates. Otherwise, you will need to modify ``api.py`` accordingly.
20+
21+
Note that you need only copy and edit the templates you are interested in updating. For example,
22+
if you are only interested in updating the ``landing_page.html`` template, then create your own version
23+
of only that same file. When pycsw detects that a custom HTML template is being used,
24+
it will look for the custom template in ``server.templates.path``. If it does not exist, pycsw
25+
will render the default HTML template for the given endpoint/request.
26+
27+
Linking to a static file in your HTML templates can be done using Jinja syntax and the exposed ``config['server']['url']``:
28+
29+
.. code-block:: html
30+
31+
<!-- CSS example -->
32+
<link rel="stylesheet" href="{{ config['server']['url'] }}/static/css/default.css">
33+
<!-- JS example -->
34+
<script src="{{ config['server']['url'] }}/static/js/main.js"></script>
35+
<!-- Image example with metadata -->
36+
<img src="{{ config['server']['url'] }}/static/img/logo.png" title="{{ config['metadata']['identification']['title'] }}" />
37+
38+
.. _`Jinja`: https://palletsprojects.com/p/jinja/
39+
.. _`Jinja documentation`: https://jinja.palletsprojects.com
40+
.. _`Flask`: https://palletsprojects.com/p/flask/
41+
.. _`Flask documentation`: https://flask.palletsprojects.com

0 commit comments

Comments
 (0)