AppendFile
A component that reads a file and returns content with new content appended at the end or within specific regions marked by alloy-{region name}-start/alloy-{region name}-end sigils.
The component can append content in two ways:
- Simple append: Content is appended to the end of the file
- Region-based append: Content is appended before the end sigil on its own line
Region sigils are line-based - any line containing “alloy-{region name}-start” or “alloy-{region name}-end” is considered a sigil.
import { AppendFile } from "@alloy-js/core";
<AppendFile path="string" regions={string[]}> {children}</AppendFile>
import { AppendFile } from "@alloy-js/core/stc";
AppendFile({ path: string, regions: string[] }).children(children)
children | optionalChildren AppendRegion children components that define content to append. |
path | string The path to the file to read and append content to. |
regions | optionalstring[] List of region IDs to append to. Defaults to [“append”] if not specified. Each region corresponds to an AppendRegion child component. |
Examples
Section titled “Examples”Simple append to end of file:
<AppendFile path="output.txt"> <AppendRegion id="append">New content to add</AppendRegion></AppendFile>
// Returns:// Original file content// New content to add
Append to specific regions:
// File content before:// Header content// <!-- alloy-main-start -->// <!-- alloy-main-end -->// Footer content
<AppendFile path="template.html" regions={["main"]}> <AppendRegion id="main">New main content</AppendRegion></AppendFile>
// Returns:// Header content// <!-- alloy-main-start -->// New main content// <!-- alloy-main-end -->// Footer content