Skip to content

Commit b27e848

Browse files
committed
add custom template dir env
1 parent e949d26 commit b27e848

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

stac_fastapi/html/middleware.py

+9-7
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from __future__ import annotations
44

55
import json
6+
import os
67
import re
78
from dataclasses import dataclass, field
89
from typing import TYPE_CHECKING, Any, List, Optional
@@ -15,14 +16,15 @@
1516
if TYPE_CHECKING:
1617
from starlette.types import ASGIApp, Message, Receive, Scope, Send
1718

18-
jinja2_env = jinja2.Environment(
19-
loader=jinja2.ChoiceLoader(
20-
[
21-
jinja2.PackageLoader(__package__, "templates"),
22-
]
23-
)
19+
templates_location = []
20+
if custom_tpl := os.environ.get("STAC_HTML_TEMPLATES_DIR"):
21+
templates_location.append(jinja2.FileSystemLoader(custom_tpl))
22+
23+
templates_location.append(jinja2.PackageLoader(__package__, "templates"))
24+
25+
DEFAULT_TEMPLATES = Jinja2Templates(
26+
env=jinja2.Environment(loader=jinja2.ChoiceLoader(templates_location))
2427
)
25-
DEFAULT_TEMPLATES = Jinja2Templates(env=jinja2_env)
2628

2729
ENDPOINT_TEMPLATES = {
2830
# endpoint Name (lower case): template name

0 commit comments

Comments
 (0)