Skip to content

Commit 8d56f37

Browse files
committed
move default HTML templates to root
1 parent ba6ff25 commit 8d56f37

18 files changed

Lines changed: 46 additions & 1 deletion

default-sample.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ server:
4343
#spatial_ranking: true
4444
#workers=2
4545
#timeout=30
46+
# templates:
47+
# path: /path/to/Jinja2/templates
48+
# static: /path/to/static/folder # css/js/img
4649

4750
logging:
4851
level: ERROR

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

docs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ pycsw |release| Documentation
3737
repositories
3838
outputschemas
3939
xslt
40+
html-templating
4041
geonode
4142
hhypermap
4243
odc

pycsw/ogc/api/util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252

5353
DATETIME_FORMAT = '%Y-%m-%dT%H:%M:%S.%fZ'
5454

55-
TEMPLATES = f'{os.path.dirname(os.path.realpath(__file__))}{os.sep}templates'
55+
TEMPLATES = f'{os.path.dirname(os.path.realpath(__file__))}{os.sep}..{os.sep}..{os.sep}templates' # noqa
5656

5757
STATIC = f'{TEMPLATES}/static'
5858

0 commit comments

Comments
 (0)