#32 closed defect (wontfix)
[PATCH] TemplateLoader with empty search path fails to load files in current working dir
Reported by: | robinbryce@… | Owned by: | cmlenz |
---|---|---|---|
Priority: | minor | Milestone: | |
Component: | Template processing | Version: | 0.1 |
Keywords: | Cc: |
Description
If a TemplateLoader is created explicitly with no arguments then its self.search_path attribute is initialised to an empty list. With the consequence that relative includes raise TemplateNotFound. ie, if source in the following xi:includes a file in the current working directory then we get an error:
Template(source).generate().filter( IncludeFilter(TemplateLoader())).render()
This works fine however:
Template(source).generate().filter( IncludeFilter(TemplateLoader(['']))).render()
The problem is the loop in markup.template:TemplateLoader.load will not execute if the search path is empty.
The attatched patch checks if search_path is empty just before the loop is encountered and if it is empty it appends the empty string. This forces the loop to execute at least once. It seemed reasonable to defer this check as late as possible so as not to interfere with derived instances or absolout file references.
Attachments (1)
Change History (3)
Changed 18 years ago by robinbryce@…
comment:1 Changed 18 years ago by cmlenz
- Milestone 0.2 deleted
- Resolution set to wontfix
- Status changed from new to closed
I don't like the idea of implicitly adding the working directory to the search path. Also, I can't reproduce the problem. One thing to note is that if you don't specify a search path, then the including template must have the absolute file name set for the include to work.
See this test case.
comment:2 Changed 18 years ago by cmlenz
In your example, the absolute file name requirement would translate too:
basedir, filename = os.path.split(path) Template(source, basedir=basedir, filename=filename).generate().filter( IncludeFilter(TemplateLoader(['']))).render()
But note that processing includes after template processing isn't what you'd normally want to do ;-)
[PATH] TemplateLoader?.load fix relative includes