├── partials ├── option_mustache ├── option_handlebars.js ├── phpcode ├── footer ├── lcsample ├── toc ├── lccompile ├── section_columns ├── option_lightncandy ├── template ├── lcresult ├── pager ├── quicksample ├── search ├── seealso ├── versions ├── section ├── sample ├── nav ├── sections ├── html_end └── html_start ├── .gitignore ├── bookdata ├── LC-FLAG_INSTANCE.yaml ├── LC-FLAG_BESTPERFORMANCE.yaml ├── LC-FLAG_JS.yaml ├── 0006-raw.yaml ├── LC-FLAG_ERROR_EXCEPTION.yaml ├── LC-FLAG_ERROR_LOG.yaml ├── 0022-blockhelper.yaml ├── LC-FLAG_ERROR_SKIPPARTIAL.yaml ├── LC-FLAG_NOESCAPE.yaml ├── LC-FLAG_JSTRUE.yaml ├── 0015-hbcomment.yaml ├── 0026-subexpression.yaml ├── LC-FLAG_PARENT.yaml ├── LC-FLAG_JSOBJECT.yaml ├── LC-FLAG_METHOD.yaml ├── 0010-comment.yaml ├── 0021-customhelper.yaml ├── LC-FLAG_PROPERTY.yaml ├── LC-FLAG_STANDALONEPHP.yaml ├── LC-FLAG_THIS.yaml ├── LC-FLAG_SLASH.yaml ├── 0030-changecontext.yaml ├── LC-FLAG_ECHO.yaml ├── LC-FLAG_JSLENGTH.yaml ├── LC-FLAG_ELSE.yaml ├── 0011-partial.yaml ├── 0029-safestring.yaml ├── 0012-delimiter.yaml ├── 0020-lookup.yaml ├── LC-FLAG_ADVARNAME.yaml ├── LC-FLAG_NAMEDARG.yaml ├── 0013-dotnotation.yaml ├── LC-FLAG_PARTIALNEWCONTEXT.yaml ├── 0024-partialcontext.yaml ├── 0007-specific-values.yaml ├── 0005-variable-escape.yaml ├── LC-FLAG_RENDER_DEBUG.yaml ├── 0023-namedarguments.yaml ├── 0027-advancedvariable.yaml ├── 0025-parentcontext.yaml ├── LC-FLAG_HBESCAPE.yaml ├── 0004-simple-variable.yaml ├── 0031-whitespace-control.yaml ├── 0032-partial-block.yaml ├── 0014-path.yaml ├── 0018-with.yaml ├── 9900-lc-options.yaml ├── LC-FLAG_RUNTIMEPARTIAL.yaml ├── 0019-each.yaml ├── LC-FLAG_EXTHELPER.yaml ├── 0003-hello.yaml ├── 9000-quickstart.yaml ├── 0009-inverted-block.yaml ├── 0016-if.yaml ├── 0028-dynamicpartial.yaml ├── 9902-lcop-partialresolver.yaml ├── 0001-intro.yaml ├── 0017-unless.yaml ├── 9903-lcop-safestring.yaml ├── 0002-install.yaml ├── 0008-block.yaml ├── 9002-helperoptions.yaml ├── 9001-customhelper.yaml ├── 9901-lcop-helperresolver.yaml ├── 9004-partials.yaml └── 9003-helperescaping.yaml ├── .eslintrc ├── composer.json ├── .github └── workflows │ └── build.yml ├── README.md ├── package.json ├── gulpfile.js ├── style.less └── helpers.js /partials/option_mustache: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /partials/option_handlebars.js: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /partials/phpcode: -------------------------------------------------------------------------------- 1 | {{{code . type="php" copy=true}}} 2 | -------------------------------------------------------------------------------- /partials/footer: -------------------------------------------------------------------------------- 1 |
4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | vendor/ 3 | generated/ 4 | composer.lock 5 | .exec_tmp_file 6 | render.php 7 | -------------------------------------------------------------------------------- /bookdata/LC-FLAG_INSTANCE.yaml: -------------------------------------------------------------------------------- 1 | description: 2 | same withFLAG_PROPERTY + FLAG_METHOD
3 | ref:
4 | - LC-FLAG_PROPERTY
5 | - LC-FLAG_METHOD
6 |
--------------------------------------------------------------------------------
/partials/lcsample:
--------------------------------------------------------------------------------
1 | {{{anchorHTML "Sample Codes"}}}
2 | FLAG_ECHO + FLAG_STANDALONEPHP now. This flag may be changed base on performance testing result in the future.
3 | ref:
4 | - LC-FLAG_ECHO
5 | - LC-FLAG_STANDALONEPHP
6 |
--------------------------------------------------------------------------------
/bookdata/LC-FLAG_JS.yaml:
--------------------------------------------------------------------------------
1 | description:
2 | simulate all supported JavaScript behavior, same with FLAG_JSTRUE + FLAG_JSOBJECT + FLAG_JSLENGTH.
3 | ref:
4 | - LC-FLAG_JSTRUE
5 | - LC-FLAG_JSOBJECT
6 | - LC-FLAG_JSLENGTH
7 |
--------------------------------------------------------------------------------
/partials/lccompile:
--------------------------------------------------------------------------------
1 | {{{anchorHTML "Compile Flags"}}}
2 | Used option: 3 | {{#each option.lightncandy}} 4 | {{.}} 5 | {{else}} 6 | {{#each option}} 7 | {{.}} 8 | {{/each}} 9 | {{/each}} 10 |
11 | {{/if}} 12 | -------------------------------------------------------------------------------- /partials/template: -------------------------------------------------------------------------------- 1 | {{> html_start}} 2 | {{> nav}} 3 |{{{description}}}
6 | {{#section_builder .}} 7 | {{> sections}} 8 | {{/section_builder}} 9 | {{>seealso}} 10 | {{>pager}} 11 | {{>search}} 12 | {{>footer}} 13 |{{{note}}}
6 | {{/if}} 7 | {{#code code type="php" copy=true result=true errorlog=errorlog}} 8 |{{.}}
10 | {{/code}}
11 | {{/each}}
12 |
--------------------------------------------------------------------------------
/bookdata/0006-raw.yaml:
--------------------------------------------------------------------------------
1 | title: Raw Output
2 | description:
3 | The output of {{{foo}}} or {{&foo}} will not be escaped by template engine.
4 | Samples:
5 | quicksample:
6 | - template: "{{{foo}}}"
7 | data:
8 | foo: Hello & Happy
9 | - template: "{{&foo}}"
10 | data:
11 | foo: Hello
12 | -------------------------------------------------------------------------------- /bookdata/LC-FLAG_ERROR_EXCEPTION.yaml: -------------------------------------------------------------------------------- 1 | description: 2 | Throw exception when template error. 3 | lcsample: 4 | - template: "{{../foo}}}OK" 5 | compileerror: true 6 | option: 7 | - FLAG_ERROR_EXCEPTION 8 | data: 9 | - template: "{{> not_found}}" 10 | compileerror: true 11 | option: 12 | - FLAG_ERROR_EXCEPTION 13 | data: 14 | -------------------------------------------------------------------------------- /bookdata/LC-FLAG_ERROR_LOG.yaml: -------------------------------------------------------------------------------- 1 | description: 2 | Print error log to stderr when template error. 3 | lcsample: 4 | - template: "{{../foo}}}OK" 5 | compileerror: true 6 | errorlog: true 7 | option: 8 | - FLAG_ERROR_LOG 9 | data: 10 | - template: "{{> not_found}}" 11 | compileerror: true 12 | errorlog: true 13 | option: 14 | - FLAG_ERROR_LOG 15 | data: 16 | -------------------------------------------------------------------------------- /partials/pager: -------------------------------------------------------------------------------- 1 |{{var}}. This option is same with handlbars.js noEscape option.
3 | lcsample:
4 | - note: The default behavior is escaping values.
5 | template: "{{foo}}"
6 | data:
7 | foo: "Love & Peace"
8 | - note: Do not escaping values.
9 | template: "{{foo}}"
10 | option:
11 | - FLAG_NOESCAPE
12 | data:
13 | foo: "Love & Peace"
14 |
--------------------------------------------------------------------------------
/bookdata/LC-FLAG_JSTRUE.yaml:
--------------------------------------------------------------------------------
1 | description:
2 | Align boolean conversion logic with JavaScript.
3 | lcsample:
4 | - note: "The default behavior: true converts to 1, false converts to empty string."
5 | template: "{{foo}}, {{bar}}"
6 | data:
7 | foo: true
8 | bar: false
9 | - note: Same behavior with handlebars.js and mustache.js.
10 | template: "{{foo}}, {{bar}}"
11 | option:
12 | - FLAG_JSTRUE
13 | data:
14 | foo: true
15 | bar: false
16 |
--------------------------------------------------------------------------------
/bookdata/0015-hbcomment.yaml:
--------------------------------------------------------------------------------
1 | title: Extended Comment
2 | hbonly: true
3 | description: "If you wanna include }} inside your comment, you can use extended comment: {{!-- comments allow }} inside it --}}"
4 | Samples:
5 | quicksample:
6 | - template: "Comment: {{! comment with }} is not ok }}"
7 | note: }} can not be placed inside a comment.
8 | - template: "Comment: {{!-- comment with }} is ok --}}"
9 | note: }} can be placed inside an extended comment.
10 | ref:
11 | - 0010-comment
12 |
--------------------------------------------------------------------------------
/bookdata/0026-subexpression.yaml:
--------------------------------------------------------------------------------
1 | title: "Subexpression"
2 | hbonly: true
3 | description: "Subexpressions allow you to invoke multiple helpers inside a tag. The result of inner helper will be arguments of outer helpers."
4 | Samples:
5 | quicksample:
6 | - template: "{{#if (iszero foo)}}Foo is zero{{/if}}"
7 | helper:
8 | iszero: >
9 | function ($arg1) {
10 | return ($arg1 === 0);
11 | }
12 | option:
13 | - FLAG_ADVARNAME
14 | data:
15 | foo: 0
16 | ref:
17 | - LC-FLAG_ADVARNAME
18 |
--------------------------------------------------------------------------------
/bookdata/LC-FLAG_PARENT.yaml:
--------------------------------------------------------------------------------
1 | description: |
2 | Support {{..}} or {{../foo}} in template. Otherwise, {{..}} or {{../foo}} will cause template error.
3 | lcsample:
4 | - note: "Error when compile {{..}}"
5 | compileerror: true
6 | errorlog: true
7 | template: "{{../foo}}OK"
8 | option:
9 | - FLAG_ERROR_LOG
10 | data:
11 | - note: "Enable handlebars.js extension {{..}}"
12 | template: "{{../foo}}OK"
13 | option:
14 | - FLAG_PARENT
15 | data:
16 | ref:
17 | - 0014-path
18 |
--------------------------------------------------------------------------------
/partials/versions:
--------------------------------------------------------------------------------
1 | ! and will be ignored. For example: {{! this is a comment}}"
3 | Samples:
4 | quicksample:
5 | - template: "{{#foo}}Ya!{{! ignored this comment}}{{/foo}}"
6 | data:
7 | foo: "OK"
8 | - template: "{{#foo}}Yes{{! foo is true}}{{/foo}}\n{{^foo}}No{{! foo is false}}{{/foo}}"
9 | data:
10 | foo: true
11 | - template: "Comment example: {{! comment with }} is not ok }}"
12 | note: }} can not be placed inside a comment.
13 | ref:
14 | - 0015-hbcomment
15 |
--------------------------------------------------------------------------------
/bookdata/0021-customhelper.yaml:
--------------------------------------------------------------------------------
1 | title: Custom Helper
2 | hbonly: true
3 | description: "You can provide custom helper to handle logic"
4 | Samples:
5 | quicksample:
6 | - template: "{{isequal foo bar}}"
7 | helper:
8 | isequal: >
9 | function ($arg1, $arg2) {
10 | return ($arg1 === $arg2) ? 'Yes' : 'No';
11 | }
12 | data:
13 | foo: 1
14 | bar: "1"
15 | ref:
16 | - http://handlebarsjs.com/expressions.html
17 | - http://handlebarsjs.com/block_helpers.html
18 | - 0023-namedarguments
19 | - 9002-helperoptions
20 | - LC-FLAG_EXTHELPER
21 |
--------------------------------------------------------------------------------
/bookdata/LC-FLAG_PROPERTY.yaml:
--------------------------------------------------------------------------------
1 | description:
2 | Support object instance attribute access; you must apply this if your data contains object.
3 | perfalert: true
4 | lcsample:
5 | - note: "The default behavior: only do associative array lookup"
6 | template: "{{foo.key}}, {{bar.key}}"
7 | data:
8 | foo:
9 | key: OK
10 | bar: (object)Array('key' => 'Good')
11 | - note: "do instance property lookup"
12 | template: "{{foo.key}}, {{bar.key}}"
13 | option:
14 | - FLAG_PROPERTY
15 | data:
16 | foo:
17 | key: OK
18 | bar: (object)Array('key' => 'Good')
19 |
--------------------------------------------------------------------------------
/bookdata/LC-FLAG_STANDALONEPHP.yaml:
--------------------------------------------------------------------------------
1 | description: |
2 | Generate stand-alone PHP codes which can be execute without LightnCandy\Runtime class. The compiled PHP code will contain scoped Runtime functions and the file size will be bigger. And, the performance will faster 5 ~10%.
3 | lcsample:
4 | - template: "{{{foo}}}"
5 | note: Default, require LightnCandy\Runtime.
6 | showcode: true
7 | option:
8 | - FLAG_JSTRUE
9 | - template: "{{{foo}}}"
10 | note: Stand alone, include used LightnCandy\Runtime functions.
11 | showcode: true
12 | option:
13 | - FLAG_STANDALONEPHP
14 | - FLAG_JSTRUE
15 |
--------------------------------------------------------------------------------
/bookdata/LC-FLAG_THIS.yaml:
--------------------------------------------------------------------------------
1 | description:
2 | Resolve {{this}} as {{.}} . Otherwise, {{this}} will lookup the variable 'this'.
3 | lcsample:
4 | - note: "The default behavior: {{this}} will look for the value of 'this' key."
5 | template: "{{this}} == {{.}}"
6 | option:
7 | - FLAG_JSOBJECT
8 | data:
9 | this: is good
10 | - note: "{{this}} means {{.}}"
11 | template: "{{this}} == {{.}}"
12 | option:
13 | - FLAG_JSOBJECT
14 | - FLAG_THIS
15 | data:
16 | this: is good
17 | ref:
18 | - 0013-dotnotation
19 |
--------------------------------------------------------------------------------
/bookdata/LC-FLAG_SLASH.yaml:
--------------------------------------------------------------------------------
1 | description:
2 | "Skip a delimiter when it behind \\ ."
3 | lcsample:
4 | - note: "The default behavior: \\ do nothing"
5 | template: "Yes, {{foo}} is \\{{foo}}"
6 | data:
7 | foo: OK
8 | - note: "You can use this way to display {{ when you do not like to use \\"
9 | template: "Show {{#with \"{{\"}}{{.}}{{/with}} in this way"
10 | data:
11 | foo: OK
12 | - note: "Use \\ to escape a delimiter"
13 | template: "Yes, {{foo}} is \\{{foo}}"
14 | option:
15 | - FLAG_SLASH
16 | data:
17 | foo: OK
18 |
--------------------------------------------------------------------------------
/bookdata/0030-changecontext.yaml:
--------------------------------------------------------------------------------
1 | title: Change Context
2 | hbonly: true
3 | description: "Custom helpers can render the inner block with new context"
4 | Samples:
5 | quicksample:
6 | - template: "{{#foo}}Hello, {{this}}{{/foo}}"
7 | option:
8 | lightncandy:
9 | - FLAG_THIS
10 | helper:
11 | foo: >
12 | function ($options) {
13 | // Apply child 'bar' of current context into inner block
14 | return $options['fn']($options['_this']['bar']);
15 | }
16 | data:
17 | bar: World
18 | ref:
19 | - 0021-customhelper
20 | - 9001-customhelper
21 |
--------------------------------------------------------------------------------
/bookdata/LC-FLAG_ECHO.yaml:
--------------------------------------------------------------------------------
1 | description: |
2 | compile to echo 'a', $b, 'c'; to improve performance. This will slow down rendering when the template and data are simple, but will improve 5% ~ 10% when the data is big and looping in the template.
3 | lcsample:
4 | - template: "A{{{foo}}}C"
5 | note: compile to 'a' . $b . 'c' when do not use FLAG_ECHO
6 | showcode: true
7 | option:
8 | - FLAG_JSTRUE
9 | - template: "A{{{foo}}}C"
10 | note: compile to echo 'a', $b, 'c' by default
11 | showcode: true
12 | option:
13 | - FLAG_ECHO
14 | ref:
15 | - LC-FLAG_BESTPERFORMANCE
16 |
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "zordius/handlebars-cookbook",
3 | "description": "A cookbook of handlebars and mustache, focus on handlebars.js , mustache.js and lightncandy usage",
4 | "homepage": "https://github.com/zordius/HandlebarsCookbook",
5 | "keywords": ["handlebars", "mustache", "template", "logicless"],
6 | "license": "MIT",
7 | "authors": [
8 | {
9 | "name": "Zordius Chen",
10 | "email": "1201409+zordius@users.noreply.github.com"
11 | }
12 | ],
13 | "require": {
14 | "php": ">=5.4.0"
15 | },
16 | "require-dev": {
17 | "zordius/lightncandy": "1.2.6"
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/bookdata/LC-FLAG_JSLENGTH.yaml:
--------------------------------------------------------------------------------
1 | description:
2 | "support {{foo.length}} when foo is an array (simulate JavaScript Array.proto.length behavior)"
3 | lcsample:
4 | - note: "The default behavior: foo.length do not look for Array.length."
5 | template: "{{foo.length}}, {{bar.length}}"
6 | data:
7 | foo: [1, 2, 3]
8 | bar:
9 | length: go
10 | width: 400
11 | - note: "foo.length will be Array.length."
12 | template: "{{foo.length}}, {{bar.length}}"
13 | option:
14 | - FLAG_JSLENGTH
15 | data:
16 | foo: [1, 2, 3]
17 | bar:
18 | length: go
19 | width: 400
20 |
--------------------------------------------------------------------------------
/bookdata/LC-FLAG_ELSE.yaml:
--------------------------------------------------------------------------------
1 | description:
2 | Resolve {{else}} or {{^}} as handlebars specification. Otherwise, {{else}} will be resolved as normal variable, and {{^}} will cause template error.
3 | lcsample:
4 | - note: "The default behavior: {{else}} will look for the value of 'else' key."
5 | template: "{{else}}"
6 | data:
7 | else: OK
8 | - template: "{{#if foo}}FOO{{else}}BAR{{/if}}"
9 | data:
10 | foo: true
11 | - template: "{{#if foo}}FOO{{else}}BAR{{/if}}"
12 | note: "{else}}will do the else logic when FLAG_ELSE enabled."
13 | option:
14 | - FLAG_ELSE
15 | data:
16 | foo: true
17 |
--------------------------------------------------------------------------------
/bookdata/0011-partial.yaml:
--------------------------------------------------------------------------------
1 | title: Partials
2 | description:
3 | "Partials begins with >, for example: {{> partial_name}}."
4 | Samples:
5 | quicksample:
6 | - template: "Hello, {{> world}}"
7 | partial:
8 | world: "{{foo}}!"
9 | data:
10 | foo: World
11 | - template: "{{>hello}}, {{> world}}\nFoo: {{#bar}}{{> world}}{{/bar}}"
12 | option:
13 | lightncandy:
14 | - FLAG_JSOBJECT
15 | note: The partial will be rendered with current context
16 | partial:
17 | world: "{{foo}}!"
18 | hello: "{{bar}}!"
19 | data:
20 | foo: World
21 | bar:
22 | foo: YA!
23 | ref:
24 | - 0024-partialcontext
25 |
--------------------------------------------------------------------------------
/bookdata/0029-safestring.yaml:
--------------------------------------------------------------------------------
1 | title: Use SafeString
2 | hbonly: true
3 | description: "You can use SafeString class to wrap your custom helper result, then it will not be escaped by handlebars.js/LightnCandy."
4 | Samples:
5 | quicksample:
6 | - template: "{{foo}}, {{bar}}"
7 | option:
8 | lightncandy:
9 | - FLAG_JSTRUE
10 | helper:
11 | foo: >
12 | function () {
13 | return 'You&Me';
14 | }
15 | bar: >
16 | function () {
17 | return new \LightnCandy\SafeString('Now&Then');
18 | }
19 | data:
20 | null
21 | ref:
22 | - 0021-customhelper
23 | - 9001-customhelper
24 | - 9003-helperescaping
25 |
--------------------------------------------------------------------------------
/bookdata/0012-delimiter.yaml:
--------------------------------------------------------------------------------
1 | title: Set Delimiter
2 | description: "Use = to set delimiters from {{ and }} to customized tag"
3 | Samples:
4 | quicksample:
5 | - template: "Hello, {{foo}}.\n{{=<* *>=}}Now, <*foo*>"
6 | note: handlebars.js do not support changing delimiters
7 | standard: mustache
8 | fail:
9 | handlebars.js: true
10 | data:
11 | foo: World
12 | - template: "Hello, {{=[[ ]]=}}\n[[> world]]\n[[> bar]]"
13 | note: Set delimiters will not change into a partial
14 | standard: mustache
15 | fail:
16 | handlebars.js: true
17 | partial:
18 | world: "{{foo}}!"
19 | bar: "<{{foo.[0].[#te#st].bar}} or {{"some string"}} or {{helper (subexpression ...)}} handlebars style extensions.
3 | lcsample:
4 | - template: "{{[foo.bar]}}"
5 | note: Default to lookup [foo then bar]
6 | data:
7 | foo.bar: GOOD!
8 | foo:
9 | bar: BAD!
10 | "[foo":
11 | "bar]": Default!
12 | - template: "{{[foo.bar]}}"
13 | note: Protect variable names by [ and ] when they contains special characters.
14 | option:
15 | - FLAG_ADVARNAME
16 | data:
17 | foo.bar: GOOD!
18 | foo:
19 | bar: BAD!
20 | ref:
21 | - 0014-path
22 | - 0027-advancedvariable
23 |
--------------------------------------------------------------------------------
/bookdata/LC-FLAG_NAMEDARG.yaml:
--------------------------------------------------------------------------------
1 | description:
2 | Enable named arguments support for partials and helpers.
3 | lcsample:
4 | - template: "{{foo abc=123}}!"
5 | note: Default is not supporting named arguments,
6 | data:
7 | abc: NO
8 | "abc=123": YES
9 | helper:
10 | foo: >
11 | function ($a) {
12 | return "OK=$a";
13 | }
14 | - template: "{{foo abc=123}}!"
15 | note: Default is not supporting named arguments,
16 | data:
17 | abc: NO
18 | "abc=123": YES
19 | option:
20 | - FLAG_NAMEDARG
21 | helper:
22 | foo: >
23 | function ($option) {
24 | return "OK={$option['hash']['abc']}";
25 | }
26 | ref:
27 | - 0021-customhelper
28 | - 0022-blockhelper
29 |
--------------------------------------------------------------------------------
/bookdata/0013-dotnotation.yaml:
--------------------------------------------------------------------------------
1 | title: Dot Notation
2 | description: Lots of mustache implementation extends the variable lookup syntax with dot notation.
3 | Samples:
4 | quicksample:
5 | - template: "Hello, {{foo.bar}}"
6 | note: "{{foo.bar}} will lookup the bar under the foo."
7 | data:
8 | foo:
9 | bar: World!
10 | - template: "Hello, {{foo.bar}}\n{{foo.bar.moo}}"
11 | note: It is fine when something is not found.
12 | data:
13 | foo:
14 | bar: World!
15 | - template: "{{#people}}\nHello, {{.}}!\n{{/people}}"
16 | note: {{.}} means current context.
17 | data:
18 | people: [John, Peter, Mary]
19 | ref:
20 | - 0014-path
21 | - LC-FLAG_THIS
22 |
--------------------------------------------------------------------------------
/partials/section:
--------------------------------------------------------------------------------
1 | file name: {{file}}
{{.}}
25 | {{/code}}
26 | {{/if}}
27 | {{/with}}
28 |
--------------------------------------------------------------------------------
/bookdata/LC-FLAG_PARTIALNEWCONTEXT.yaml:
--------------------------------------------------------------------------------
1 | description:
2 | Create a new context for the partial. This option is same with handlbars.js explicitPartialContext option.
3 | lcsample:
4 | - note: The default behavior is reusing current context when there is no argument for the partial.
5 | template: "{{> foo}}"
6 | partial:
7 | foo: "BAR:{{bar}}"
8 | data:
9 | bar: "Good!"
10 | - note: Create an empty object as new context for the partial without argument. FLAG_RUNTIMEPARTIAL is required.
11 | template: "{{> foo}}"
12 | partial:
13 | foo: "BAR:{{bar}}"
14 | data:
15 | bar: "Good!"
16 | option:
17 | - FLAG_PARTIALNEWCONTEXT
18 | - FLAG_RUNTIMEPARTIAL
19 | ref:
20 | - LC-FLAG_RUNTIMEPARTIAL
21 |
--------------------------------------------------------------------------------
/partials/sample:
--------------------------------------------------------------------------------
1 | {{#render}}
2 | {{#if note}}
3 | {{{note}}}
4 | {{/if}} 5 | {{> (str_join "option" type sep="_")}} 6 | {{#if partial}} 7 | Partials: 8 || {{@key}} | {{.}} |
|---|
Check the code to know used helper codes
23 | {{/if}} 24 | {{{code @code type=@codeType copy=true collapse=collapse}}} 25 | {{/render}} 26 | -------------------------------------------------------------------------------- /bookdata/0024-partialcontext.yaml: -------------------------------------------------------------------------------- 1 | title: Change Partial Context 2 | hbonly: true 3 | description: "You can change partial context by providing more arguments after the partial name" 4 | Samples: 5 | quicksample: 6 | - template: "{{>foo bar}}" 7 | note: The first argument will be new context for the partial 8 | partial: 9 | foo: "{{moo}}" 10 | option: 11 | lightncandy: 12 | - FLAG_RUNTIMEPARTIAL 13 | data: 14 | bar: 15 | moo: GOOD! 16 | - template: "{{>foo bar moo='abc'}}" 17 | note: Named arguments will be merged into context 18 | partial: 19 | foo: "{{moo}}" 20 | option: 21 | lightncandy: 22 | - FLAG_RUNTIMEPARTIAL 23 | - FLAG_NAMEDARG 24 | data: 25 | bar: 26 | moo: GOOD! 27 | ref: 28 | - LC-FLAG_RUNTIMEPARTIAL 29 | - LC-FLAG_NAMEDARG 30 | -------------------------------------------------------------------------------- /bookdata/0007-specific-values.yaml: -------------------------------------------------------------------------------- 1 | title: Specific Values 2 | description: 3 | Input values other than string will be rendered in specific way. 4 | Samples: 5 | quicksample: 6 | - template: "{{{foo}}}" 7 | option: 8 | lightncandy: 9 | - FLAG_JSTRUE 10 | data: 11 | foo: true 12 | - template: "{{{foo}}}" 13 | option: 14 | lightncandy: 15 | - FLAG_JSTRUE 16 | data: 17 | foo: false 18 | - template: "{{{foo}}}" 19 | option: 20 | lightncandy: 21 | - FLAG_JSOBJECT 22 | data: 23 | foo: 24 | bar: foo is object 25 | - template: "{{{foo}}}" 26 | option: 27 | lightncandy: 28 | - FLAG_JSOBJECT 29 | data: 30 | foo: [is, an, array] 31 | - template: "{{{foo}}}" 32 | option: 33 | lightncandy: 34 | - FLAG_JSOBJECT 35 | fail: 36 | mustache: true 37 | data: 38 | -------------------------------------------------------------------------------- /partials/nav: -------------------------------------------------------------------------------- 1 | 19 | -------------------------------------------------------------------------------- /bookdata/0005-variable-escape.yaml: -------------------------------------------------------------------------------- 1 | title: Variable Escaping 2 | description: 3 | The output of{{foo}} will be escaped by template engine.
4 | Samples:
5 | quicksample:
6 | - template: "{{foo}}"
7 | data:
8 | foo: Hello & Happy
9 | - template: "{{foo}}"
10 | note: mustache.js also escapes /
11 | different: true
12 | data:
13 | foo: Hello
14 | - template: "{{foo}}" 15 | note: handlebars.js escapes' , ` and = in his way
16 | different: true
17 | data:
18 | foo: Quotes as ' and " and ` , equal is =
19 | - template: "{{foo}}"
20 | note: The escaping behavior of Lightncandy can be configured to same with handlebars exactly.
21 | different: true
22 | option:
23 | lightncandy: [FLAG_HBESCAPE]
24 | data:
25 | foo: Quotes as ' and " and ` , equal is =
26 | ref:
27 | - LC-FLAG_HBESCAPE
28 |
--------------------------------------------------------------------------------
/bookdata/LC-FLAG_RENDER_DEBUG.yaml:
--------------------------------------------------------------------------------
1 | description:
2 | Generate debug template to show error when rendering. With this flag, the performance of rendering may be slowed.
3 | lcsample:
4 | - template: "OK!{{foo}}"
5 | note: Compile template to debug version, output HTML error hint for browser when variable not found.
6 | option:
7 | - FLAG_RENDER_DEBUG
8 | renderoption:
9 | debug:
10 | - DEBUG_TAGS_HTML
11 | - template: "OK!{{foo}}"
12 | note: Compile template to debug version, output ANSI error hint for terminal when variable not found.
13 | option:
14 | - FLAG_RENDER_DEBUG
15 | renderoption:
16 | debug:
17 | - DEBUG_TAGS_ANSI
18 | - template: "OK!{{foo}}"
19 | note: Compile template to debug version, output to PHP error log when variable not found.
20 | option:
21 | - FLAG_RENDER_DEBUG
22 | renderoption:
23 | debug:
24 | - DEBUG_ERROR_LOG
25 |
26 | ref:
27 | - 9003-helperescaping
28 |
--------------------------------------------------------------------------------
/bookdata/0023-namedarguments.yaml:
--------------------------------------------------------------------------------
1 | title: Named Arguments
2 | hbonly: true
3 | description: "You can pass named arguments into custom helper or partial."
4 | Samples:
5 | quicksample:
6 | - template: "{{helper bar foo=123}}"
7 | helper:
8 | helper: >
9 | function ($arg0, $options) {
10 | return $arg0 . ',' . $options['hash']['foo'];
11 | }
12 | option:
13 | lightncandy:
14 | - FLAG_NAMEDARG
15 | data:
16 | bar: ABC
17 | foo: DEF
18 | - template: "{{{link href=foo title=bar}}}"
19 | helper:
20 | link: >
21 | function ($options) {
22 | return '' . $options['hash']['title'] . '';
23 | }
24 | option:
25 | lightncandy:
26 | - FLAG_NAMEDARG
27 | data:
28 | bar: Yahoo!
29 | foo: http://yahoo.com/
30 | ref:
31 | - 0021-customhelper
32 | - 0022-blockhelper
33 | - 0024-partialcontext
34 | - LC-FLAG_RUNTIMEPARTIAL
35 | - LC-FLAG_NAMEDARG
36 |
--------------------------------------------------------------------------------
/partials/sections:
--------------------------------------------------------------------------------
1 | {{#main_section}}
2 | {{#if (eq @section "lcsample")}}
3 | {{>lcsample}}
4 | {{else if (eq @section "lccompile")}}
5 | {{>lccompile}}
6 | {{else if (eq @section "lcresult")}}
7 | {{>lcresult}}
8 | {{else if (eq @section "hbonly")}}
9 | This is a handlebars.js extension, mustache do not support this.
10 | {{else if (eq @section "perfalert")}} 11 |This flag cause bad rendering performance, do not enable it unless you need this feature anyway.
12 | {{else}} 13 | {{{anchorHTML @section}}} 14 |