compileTemplateFile cannot open File
sdmcallister opened this issue · 4 comments
sdmcallister commented
In test.nim I have:
import nimja
proc renderNimjaStr(ss:string, l: seq[string]): string =
compileTemplateStr(
"""<div><p>{{ss}}</p>{% for (i) in l %}<p>{{i}}</p>{% endfor %}</div>"""
)
proc renderNimjaFile(ss:string, l: seq[string]): string =
compileTemplateFile("index.nwt")
echo renderNimjaStr("Foo", @["hello", "world"])
echo renderNimjaFile("Foo", @["hello", "world"])
in the same dir i have index.nwt:
<div><p>{{ss}}</p>{% for (i) in l %}<p>{{i}}</p>{% endfor %}</div>
Running nim c -r test.nim I get:
template/generic instantiation of `compileTemplateFile` from here
sharedhelper.nim(9, 15) Error: cannot open file: index.nwt
renderNimjaStr works fine.
enthus1ast commented
Please try:
compileTemplateFile(getScriptDir() / "index.nwt")
sdmcallister commented
I changed the code to:
proc renderNimjaFile(ss:string, l: seq[string]): string =
compileTemplateFile(getScriptDir() / "index.nwt")
running `nim c -r Error:
Error: type mismatch: got <string, string>
but expected one of:
func `/`(x: Uri; path: string): Uri
first type mismatch at position: 1
required type for x: Uri
but expression '
getProjectPath()' is of type: string
proc `/`(x, y: float): float
first type mismatch at position: 1
required type for x: float
but expression '
getProjectPath()' is of type: string
proc `/`(x, y: float32): float32
first type mismatch at position: 1
required type for x: float32
but expression '
getProjectPath()' is of type: string
proc `/`(x, y: int): float
first type mismatch at position: 1
required type for x: int
but expression '
getProjectPath()' is of type: string
expression:
getProjectPath() /
"index.nwt"
enthus1ast commented
yes you also must do
import os
for "/"
sdmcallister commented
Darn I feel smart. I swear I did this earlier and it also failed, but clearly I imagined that. Ok, it works. Thanks!