> For the complete documentation index, see [llms.txt](https://docs.realmacsoftware.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.realmacsoftware.com/elements/api-reference/components/shared-files/templates.md).

# Templates

Shared Template Folder

The `templates` folder contains HTML or PHP files that are injected into the page when any component from your pack is used. These templates typically load [shared assets](/elements/api-reference/components/shared-files/assets.md) or add global scripts and styles.

## Injection Points

Templates must be placed in one of four subfolders, each corresponding to a specific location in the HTML document:

| Folder      | Location          | Use Cases                                      |
| ----------- | ----------------- | ---------------------------------------------- |
| `headStart` | Start of `<head>` | Core libraries that must load first, polyfills |
| `headEnd`   | End of `<head>`   | Styles, deferred scripts, additional libraries |
| `bodyStart` | Start of `<body>` | Early initialization, loading indicators       |
| `bodyEnd`   | End of `<body>`   | Feature scripts, animations, scroll handlers   |

## Folder Structure

```
shared/
  templates/
    headStart/
      setup.html
    headEnd/
      styles.html
      directives.html
    bodyEnd/
      animations.html
```

You can have multiple template files in each folder. There is no restriction on file naming—all files in each folder will be included.

## Supported File Types

| Type    | Description                                 |
| ------- | ------------------------------------------- |
| `.html` | HTML content, inline scripts, inline styles |
| `.php`  | PHP code for server-side processing         |

Templates can contain inline code within `<script>` and `<style>` tags, as well as references to shared assets using `{{assetPath}}`.

## Single Inclusion

Shared templates are included **once per page** per element pack, regardless of how many components from that pack are on the page. This ensures libraries and initialization code are not duplicated.

{% hint style="info" %}
HTML, PHP, CSS, and JS files are supported in the [Templates folder at the single Component](/elements/api-reference/components/templates.md) level for component-specific templates.
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.realmacsoftware.com/elements/api-reference/components/shared-files/templates.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
