This article mainly introduces the introduction and usage of simple js template engine simplite. For more information, see https://github.com/zhangshaolong/simplitewelcome. Features:
1: The amount of code is small, and the learning cost is low;
2: The default jsp syntax tag method. jsp-related users can directly write templates based on jsp syntax;
3: Use native js syntax for logic processing. as long as you are familiar with js syntax, you can get started directly without learning costs.
4: supports all native js syntaxes as code logic snippets and a broad writing format.
5: Support for redefinition of template language tags. the default logical tags are <% and %>, and the default attribute tags are <% = and %>.
6: nested subtemplates are supported. by default (no data parameters are passed), the subtemplates share the parent template data. you can set the dataset used by the subtemplate by passing parameters.
7: supports dynamic import templates and embedding of multiple templates, as long as the imported template is not a circular dependency template, it can be processed normally.
8: supports the use of Simplite in subtemplates. the complete set of data transmitted by the field specified by dataKey. the default value is "_ this". For datasets such as arrays and numbers, use Simplite. dataKey is easy to get data.
9: The template processing process can be manually organized by using templates and pure static functions in object-oriented mode.
10: in addition to accessing the parent template data, you can also provide any data in the method scope as a dataset. for example, if there is an arr globally, you can include (tmplt, arr)
Syntax:
We can see that when using include, you can use a sub-template to input a specified dataset as a data source. for a complex multi-layer structure, you can well control the data structure of each template.