Skip to content

Commit

Permalink
add placeholders
Browse files Browse the repository at this point in the history
Signed-off-by: George Lemon <[email protected]>
  • Loading branch information
georgelemon committed Mar 17, 2024
1 parent f67850d commit f413c86
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions example/initializer.nim
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import ../src/tim
# Setup Tim Engine
#
var
timl = newTim(
timl =
newTim(
src = "templates",
output = "storage",
basepath = currentSourcePath(),
minify = true,
indent = 2
indent = 2,
showHtmlError = true
)

# some read-only data to expose inside templates
Expand Down Expand Up @@ -48,6 +50,16 @@ let globalData = %*{
var timThread: Thread[void]
proc precompileEngine() {.thread.} =
{.gcsafe.}:
# let's add some placeholders
const snippetCode2 = """
div.alert.aler.dark.rounded-0.border-0.mb-0 > p.mb-0: "Alright, I'm the second snippet loaded by #topbar placeholder."
"""
let snippetParser = parseSnippet("mysnippet", readFile("./mysnippet.timl"))
timl.addPlaceholder("topbar", snippetParser.getAst)

let snippetParser2 = parseSnippet("mysnippet2", snippetCode2)
timl.addPlaceholder("topbar", snippetParser2.getAst)

timl.precompile(
waitThread = true,
global = globalData,
Expand Down

0 comments on commit f413c86

Please sign in to comment.