[html-template-devel] TMPL_INCLUDE and *default-template-pathname*

Hello, I have noticed some strange behaviour while using TMPL_INCLUDE tags when *default-template-pathname* is set to some relative path. I am not sure whether its a bug or not, but it sure doesn't work as I expect it to - Let's start with a some directory - CL-USER(5): *default-pathname-defaults* #P"/Users/chaitanya/lisp/" Now I define a string with the TMPL_INCLUDE tag. CL-USER(7): (setf *tmpl-string* "before test || <!-- TMPL_INCLUDE 'temp/test-template' --> || after test") "before test || <!-- TMPL_INCLUDE 'temp/test-template' --> || after test" Calling fill-and-print-template works fine here. CL-USER(8): (html-template:fill-and-print-template *tmpl-string* nil) before test || Just a test template - || after test The value of *default-template-pathname* currently is CL-USER(11): html-template:*default-template-pathname* #P"" Now we will change it to #p"temp/" CL-USER(12): (setf html-template:*default-template-pathname* #p"temp/") #P"temp/" And we also change *tmpl-string* - CL-USER(13): (setf *tmpl-string* "before test || <!-- TMPL_INCLUDE 'test-template' --> || after test") "before test || <!-- TMPL_INCLUDE 'test-template' --> || after test" Now calling fill-and-print-template doesn't work - CL-USER(14): (html-template:fill-and-print-template *tmpl-string* nil) Error: File #P"temp/temp/test-template" does not exist. [condition type: FILE-ERROR] Restart actions (select using :continue): 0: Return to Top Level (an "abort" restart). 1: Abort entirely from this (lisp) process. Upon looking at the source code, I saw that merge-pathnames was being called both while processing the TMPL_INCLUDE tag in create-template-printer-aux and while actually creating the template printer in create-template-printer. And indeed, tracing merge-pathnames reveals that this is what's happening - CL-USER(17): (html-template:fill-and-print-template *tmpl-string* nil) 0[2]: (MERGE-PATHNAMES "test-template" #P"temp/") 0[2]: returned #P"temp/test-template" 0[2]: (MERGE-PATHNAMES #P"temp/test-template" #P"temp/") 0[2]: returned #P"temp/temp/test-template" 0[2]: (MERGE-PATHNAMES #P"temp/temp/test-template") 0[2]: returned #P"/Users/chaitanya/lisp/temp/temp/test-template" 0[2]: (MERGE-PATHNAMES #P"temp/temp/test-template") 0[2]: returned #P"/Users/chaitanya/lisp/temp/temp/test-template" Error: File #P"temp/temp/test-template" does not exist. [condition type: FILE-ERROR] Restart actions (select using :continue): 0: Return to Top Level (an "abort" restart). 1: Abort entirely from this (lisp) process. This seems like a bug to me. Is this how its supposed to work? If yes, then how do I solve the above problem? (I don't want to set html-template:*default-template-pathname* to an absolute path) Thanks, Chaitanya

On Wed, 28 Mar 2007 16:26:28 +0530, Chaitanya Gupta <mail@chaitanyagupta.com> wrote:
This seems like a bug to me. Is this how its supposed to work? If yes, then how do I solve the above problem? (I don't want to set html-template:*default-template-pathname* to an absolute path)
I'm not sure I'd call this a bug - I definitely wouldn't expect the default pathname to be a relative one. What are you trying to achieve by this? Cheers, Edi.

Edi Weitz wrote:
On Wed, 28 Mar 2007 16:26:28 +0530, Chaitanya Gupta <mail@chaitanyagupta.com> wrote:
This seems like a bug to me. Is this how its supposed to work? If yes, then how do I solve the above problem? (I don't want to set html-template:*default-template-pathname* to an absolute path)
I'm not sure I'd call this a bug - I definitely wouldn't expect the default pathname to be a relative one. What are you trying to achieve by this?
The reason I was setting default pathname to a relative one was because I want the app to be free of any absolute paths i.e I should be able to move the whole thing from one directory to another without any changes whatsoever. In any case, I realized the solution is simple enough. Evaluating this form on startup - (setf html-template:*default-template-pathname* (merge-pathnames #p"templates/" *default-pathname-defaults*)) Sets default template pathname to an absolute one and also keeps our app pathname agnostic. Thanks, Chaitanya
participants (2)
-
Chaitanya Gupta
-
Edi Weitz