Skip to content
This repository

Some suggestions for clarification of advanced examples. #13

wants to merge 1 commit into from

2 participants

Paul d'Aoust kgcab
Paul d'Aoust

Hi there. I changed the explanation of a couple of the advanced examples -- just two things I didn't quite understand at first, and thought could be clarified.

After trying unsuccessfully to use def.loadfile() to bring in a partial, I did a search of the source and found it was meant as an example of how to augment def, so I thought it might be good to indicate that loadfile() isn't a built-in function.

Ummm, what else... I added a description of the two runtime conditionals at the end, and added an example of a loop.


loadfile() would have to be accessible in the local context. It would not be found in the def associative array. doT strips off the 'def.' in definition directives before evaluating the remainder (assuming a matching string is not found in the def aa - in which case the directive is ignored - there's no way to change a value once it is set in the def aa).

Seems like most of the examples, excepting withdoT.js, are missing some setup to make them work properly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 8 additions and 1 deletion. Show diff stats Hide diff stats

  1. +8 1 examples/advancedsnippet.txt
9 examples/advancedsnippet.txt
@@ -3,7 +3,7 @@ Advanced templating: illustrates defines and includes.
3 3 Include external snippet defined in a variable:
4 4 {{#def.externalsnippet}}
5 5
6   -Load external template from a file:
  6 +Load external template from a file (using a custom loadFile() method attached to def; see /examples/withdoT.js):
7 7 {{#def.loadfile('/snippet.txt')}}
8 8
9 9 Load external template from a file and cache in a variable:
@@ -38,6 +38,7 @@ Set xyz to 1 and exclude result from output:
38 38 Compare xyz to 1, show 'xyz is not 1' if false:
39 39 {{ === 1 || 'xyz is not 1'}}
40 40
  41 +Conditionals to be evaluated at runtime, with conditions pre-evaluated at compile time:
41 42 {{ if ({{#!}}) { }}
42 43 {{}} is falsy
43 44 {{ } }}
@@ -46,3 +47,9 @@ Compare xyz to 1, show 'xyz is not 1' if false:
46 47 if(true) block
47 48 {{ } }}
48 49
  50 +Create a series of elements using a loop at runtime
  51 +<ul>
  52 + {{ for (i in it.people) { }}
  53 + <li>My name is {{=it.people[i].firstName}}</li>
  54 + {{ } }}
  55 +</ul>

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.