# Complex Script


@include "header.md"


## Main Content


This is the main content section.


@include "examples/code-sample.md"


## Conclusion


@include "footer.md"
```

## Error Handling

[Section titled “Error Handling”](#error-handling)

If an included file cannot be found or read, the `@include` directive is replaced with an HTML comment containing the error message:

```markdown
<!-- Error including missing-file.txt: File not found: /path/to/missing-file.txt -->
```

This ensures that your script continues to work even when included files are missing, while providing clear feedback about what went wrong.

## Use Cases

[Section titled “Use Cases”](#use-cases)

The `@include` directive is useful for:

* **Reusable templates**: Share common greetings, instructions, or examples across multiple scripts
* **Modular prompts**: Break large prompts into manageable, focused files
* **Content organization**: Keep related content in separate files for better maintainability
* **Team collaboration**: Allow team members to work on different parts of a prompt independently

## Comparison with importTemplate

[Section titled “Comparison with importTemplate”](#comparison-with-importtemplate)

The `@include` directive is different from the programmatic `importTemplate` function:

| Feature            | `@include` directive               | `importTemplate` function                                  |
| ------------------ | ---------------------------------- | ---------------------------------------------------------- |
| **Usage**          | Markdown scripts (`.genai.md`)     | JavaScript/TypeScript scripts (`.genai.mjs`, `.genai.mts`) |
| **Processing**     | Content replacement during parsing | Runtime template rendering                                 |
| **Variables**      | No variable interpolation          | Supports Mustache/Jinja variables                          |
| **Error handling** | HTML comments for missing files    | Runtime errors                                             |
| **File types**     | Any text file                      | Template files with variable syntax                        |

Choose `@include` for simple content inclusion in markdown scripts, and `importTemplate` for dynamic template rendering with variables in JavaScript/TypeScript scripts.