@microsoft/fast-element > ViewTemplate > create
ViewTemplate.create() method
Processes the tagged template literal's static strings and interpolated values and creates a ViewTemplate.
For each interpolated value: 1. Functions (binding expressions, e.g., x => x.name) → wrapped in a one-way HTMLBindingDirective 2. Binding instances → wrapped in an HTMLBindingDirective 3. HTMLDirective instances → used as-is 4. Static values (strings, numbers) → wrapped in a one-time HTMLBindingDirective
Each directive's createHTML() is called with an add callback that registers the factory in the factories record under a unique ID and returns that ID. The directive inserts a placeholder marker (e.g., fast-abc123{0}fast-abc123) into the HTML string so the compiler can later find and associate it with the factory.
Aspect detection happens here too: the lastAttributeNameRegex checks whether the placeholder appears inside an attribute value, and if so, assignAspect() sets the correct DOMAspect (attribute, property, event, etc.) based on the attribute name prefix.
Signature:
static create<TSource = any, TParent = any>(strings: string[], values: TemplateValue<TSource, TParent>[], policy?: DOMPolicy): ViewTemplate<TSource, TParent>;
Parameters
|
Parameter |
Type |
Description |
|---|---|---|
|
strings |
string[] |
The static strings to create the template with. |
|
values |
TemplateValue<TSource, TParent>[] |
The dynamic values to create the template with. |
|
policy |
DOMPolicy |
(Optional) The DOMPolicy to associated with the template. |
Returns:
ViewTemplate<TSource, TParent>
A ViewTemplate.
Remarks
This API should not be used directly under normal circumstances because constructing a template in this way, if not done properly, can open up the application to XSS attacks. When using this API, provide a strong DOMPolicy that can properly sanitize and also be sure to manually sanitize all static strings particularly if they can come from user input.