TemplateFile
A component that reads a template file and replaces variable placeholders with actual values.
Template files can contain variable placeholders in the format
{{ variable_name }} which will be replaced with values from TemplateVariable
children components. Whitespace around variable names is ignored, so
{{ name }}, {{name}}, and {{ name }} are all equivalent.
import { TemplateFile } from "@alloy-js/core";
<TemplateFile path="string" src="string"> {children}</TemplateFile>import { TemplateFile } from "@alloy-js/core/stc";
TemplateFile({ path: string, src: string }).children(children)| children | optionalChildrenTemplate variable children components. |
| path | stringThe path to write the compiled template to. |
| src | stringThe file path of the template. |
Examples
Section titled “Examples”Basic usage with template variables:
// Template file content (greeting.txt):// "Hello {{ name }}! You are {{ age }} years old."
<TemplateFile src="greeting.txt" path="output.txt"> <TemplateVariable name="name" value="John" /> <TemplateVariable name="age" value="25" /></TemplateFile>Using children instead of value prop:
// Template file content (welcome.txt):// "Welcome {{ greeting }}!"
<TemplateFile src="welcome.txt" path="output.txt"> <TemplateVariable name="greeting">Hello World</TemplateVariable></TemplateFile>Complex template with multiple variables:
// Template file content (profile.txt):// "Name: {{ name }}Age: {{ age }}Location: {{ location }}"
<TemplateFile src="profile.txt" path="profile-output.txt"> <TemplateVariable name="name" value="Alice" /> <TemplateVariable name="age">30</TemplateVariable> <TemplateVariable name="location" value="New York" /></TemplateFile>