1 |
|
2 | # Igo Views
|
3 |
|
4 | Igo uses the [Dust](http://www.dustjs.com/) templating engine. This module is maintained by LinkedIn (https://github.com/linkedin/dustjs).
|
5 |
|
6 | The templates files are located in the `/views` directory.
|
7 |
|
8 | ```js
|
9 | // will render "/views/users/show.dust"
|
10 | res.render('users/show');
|
11 | ```
|
12 |
|
13 | ## Template syntax
|
14 |
|
15 | The Dust.js documentation can be found on http://www.dustjs.com/
|
16 |
|
17 | ## i18n
|
18 |
|
19 | Igo uses [i18next](http://i18next.com/), which is a great module so make sure that your read their [documentation](http://i18next.com/docs).
|
20 | Here is the default configuration:
|
21 |
|
22 | ```js
|
23 | config.i18n = {
|
24 | whitelist: [ 'en', 'fr' ],
|
25 | preload: [ 'en', 'fr' ],
|
26 | fallbackLng: 'en',
|
27 | backend: {
|
28 | loadPath: 'locales/{{lng}}/{{ns}}.json',
|
29 | },
|
30 | detection: {
|
31 | order: [ 'querystring', 'path', 'cookie' ],
|
32 | lookupPath: 'lang',
|
33 | lookupQuerystring: 'lang',
|
34 | lookupCookie: 'lang',
|
35 | caches: [ 'cookie' ]
|
36 | },
|
37 | };
|
38 | ```
|
39 |
|
40 | **Usage:**
|
41 | Use the `{@t key="mykey" /}` syntax to insert internationalized wordings.
|
42 |
|
43 | Translations are defined in the `/locales/{LANG}/translation.json` files.
|
44 |
|
45 | ```json
|
46 | {
|
47 | "mykey": "Hello World"
|
48 | }
|
49 | ```
|
50 |
|
51 |
|
52 | ## View helpers
|
53 |
|
54 | Igo allows to define custom Dust Helpers in the `/app/helpers.js` file.
|
55 |
|
56 | ```js
|
57 | module.exports.init = function(dust) {
|
58 |
|
59 | // define your dust helpers here
|
60 | // (example taken from http://www.dustjs.com/docs/helper-api/)
|
61 | dust.helpers.period = function(chunk, context, bodies, params) {
|
62 | var location = params.location, body = bodies.block;
|
63 | if (location === 'start') {
|
64 | chunk.write('.');
|
65 | chunk.render(body, context);
|
66 | } else if (location === 'end') {
|
67 | chunk.render(body, context);
|
68 | chunk.write('.');
|
69 | } else {
|
70 | dust.log('WARN', 'missing parameter "location" in period helper');
|
71 | }
|
72 | return chunk;
|
73 | };
|
74 |
|
75 | };
|
76 | ```
|