@@ -46,17 +46,26 @@ def setup(app):
46
46
47
47
# this is hack is needed to use our layout.html on ReadTheDocs
48
48
from sphinx .jinja2glue import BuiltinTemplateLoader
49
+ from jinja2 import TemplateNotFound
49
50
class MyTemplateLoader (BuiltinTemplateLoader ):
50
51
def get_source (self , environment , template ):
51
- print "(MyTemplateLoader.get_source) searching for" , template
52
52
# If template name in Jinja's "extends" is prepended with "!"
53
53
# Sphinx skips project's template paths.
54
54
# In BuiltinTemplateLoader self.templatepathlen is used to remove
55
55
# project's template paths and leave only Sphinx's paths.
56
56
# This hack should leave the last path, so "!layout.html" will find
57
57
# the template from Fityk. To avoid recursion, Fityk template
58
58
# is not using "!".
59
- self .templatepathlen -= 1
60
- return BuiltinTemplateLoader .get_source (self , environment , template )
61
- self .templatepathlen += 1
62
-
59
+ print ("\n (MyTemplateLoader.get_source) searching for %s" % template )
60
+ loaders = self .loaders
61
+ # exclamation mark starts search from theme
62
+ if template .startswith ('!' ):
63
+ loaders = loaders [self .templatepathlen - 1 :]
64
+ template = template [1 :]
65
+ for loader in loaders :
66
+ print ("\t trying in: %s" % ":" .join (loader .searchpath ))
67
+ try :
68
+ return loader .get_source (environment , template )
69
+ except TemplateNotFound :
70
+ pass
71
+ raise TemplateNotFound (template )
0 commit comments