From 62ad3f003f1044cb350d87e5524f235ce77b1725 Mon Sep 17 00:00:00 2001 From: "David Krause (enthus1ast)" Date: Fri, 9 Aug 2024 23:10:14 +0200 Subject: [PATCH 1/2] readme baseDir --- .gitignore | 31 +++++++++++++++++++++++++++++++ readme.md | 11 +++++++++-- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 476f601..e25f129 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,34 @@ tests/basic/test_simple tests/basic/test_while src/nimja/parser src/nimja/sharedhelper +tests/basic/NOT_READY_test_raw +tests/basic/test_endless_iterator +tests/basic/test_file_foo_html +tests/basic/test_iterator +tests/basic/test_lexer +tests/basic/test_module_import +tests/basic/test_nimjautils +tests/basic/test_proc +tests/basic/test_proc_import +tests/basic/test_scope +tests/basic/test_self +tests/basic/test_shorhands +tests/basic/test_strparse +tests/basic/test_tmplf_with_context +tests/basic/test_tmpls_with_context +tests/basic/test_tokens_before_extend +tests/basic/test_triple +tests/basic/test_unicode +tests/basic/test_when +tests/basic/test_whitespacecontrol +tests/basic/test_blockInBlock +tests/basic/test_blockNotExtendedMaster +tests/basic/test_blockRenderMasterDirectly +tests/basic/test_case +tests/basic/test_condense_strings +tests/basic/test_double_extend +tests/basic/test_doublicated_blocks +tests/basic/theModule/theModule +tests/bugs/test_nwt_bug4_debug +examples/prologue/serverPrologue +examples/prologue/serverJester diff --git a/readme.md b/readme.md index 5f143de..ad9a7d2 100644 --- a/readme.md +++ b/readme.md @@ -474,6 +474,9 @@ template and therefore can be included. This way you create reusable template blocks to use all over your webpage. +(Since Nimja 0.9.0) If you import other templates, make sure to use the `baseDir` param with +`tmpls`, `tmplf`, `compileTemplateString` and `compileTemplateFile`. + partials/_user.nimja: ```twig
@@ -501,6 +504,8 @@ a child template can extend a master template. So that placeholder blocks in the master are filled with content from the child. +(Since Nimja 0.9.0) If you extend other templates, make sure to use the `baseDir` param with +`tmpls`, `tmplf`, `compileTemplateString` and `compileTemplateFile`. partials/_master.nimja ```twig @@ -1113,14 +1118,16 @@ Changelog - 0.9.0 - BREAKING CHANGE! - in order to fix #15 & #89 and to enable nimja components imported from other modules, - all proc (`tmpls`, `tmplf`, `compileTemplateString` and `compileTemplateFile`) got an `baseDir` param: + all proc (`tmpls`, `tmplf`, `compileTemplateString` and `compileTemplateFile`) got a `baseDir` param: ``` compileTemplateStr("""{{importnimja "some/template.nimja"}}""", baseDir = getScriptDir()) tmpls("""{{importnimja "some/template.nimja"}}""", baseDir = getScriptDir()) compileTemplateFile("some/template.nimja", baseDir = getScriptDir()) tmpls("some/template.nimja", baseDir = getScriptDir()) ``` - The use of `tmplf(getScriptDir() / "foo.nimja")` is discourage. It could still work in some cirumstances though. + The use of `tmplf(getScriptDir() / "foo.nimja")` is discourage, use `tmplf("foo.nimja", baseDir = getScriptDir())` instead. + The old way could still work in some cirumstances though. + But its neccesary if you plan to import your nimja template code into other code. - 0.8.7 - Removed unused `NImport`. - Error on uneven `when` blocks. From 50cb262107caf26037fd9f1481ab71b64438d134 Mon Sep 17 00:00:00 2001 From: "David Krause (enthus1ast)" Date: Mon, 12 Aug 2024 08:39:47 +0200 Subject: [PATCH 2/2] Signed-off-by: David Krause (enthus1ast) --- readme.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/readme.md b/readme.md index ad9a7d2..50c6e6e 100644 --- a/readme.md +++ b/readme.md @@ -284,7 +284,7 @@ compileTemplateStr ```nim proc myRenderProc(someParam: string): string = - compileTemplateStr("some nimja code {{someParam}}") + compileTemplateStr("some nimja code {{someParam}}", baseDir = getScriptDir()) echo myRenderProc("test123") ``` @@ -297,6 +297,8 @@ iteratior section. assign calls to a variable. The default is `result`. If you want it to use another variable set it in `varname` +`baseDir` is needed when you want to import/extend templates! + A context can be supplied to the `compileTemplateString` (also `compileTemplateFile`), to override variable names: ```nim