Skip to content

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:

  1. Simple append: Content is appended to the end of the file
  2. 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>
childrenoptionalChildren

AppendRegion children components that define content to append.

pathstring

The path to the file to read and append content to.

regionsoptionalstring[]

List of region IDs to append to. Defaults to [“append”] if not specified. Each region corresponds to an AppendRegion child component.

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