> For the complete documentation index, see [llms.txt](https://cbwire.ortusbooks.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cbwire.ortusbooks.com/3.x/essentials/templates.md).

# Templates

Templates are the HTML section of your [Components](/3.x/essentials/components.md) and consist of any valid CFML tags. This includes \<cfif>, \<cfloop>, etc.

```html
<cfscript>
    // Component stuff goes here
    function doSomething() {}
</cfscript>

<cfoutput>
    <!-- HTML template goes here -->
    <div>
        <button wire:click="doSomething">Click here</button>
        <!-- Any valid CFML here -->
        <cfif datePart( 'h', now() ) lt 12>
            <p>Good morning!</p>
        <cfelse>
            <p>Good afternoon!</p>
        </cfif>
    </div>
</cfoutput>
```

## Outer Element

Your templates must have a single outer element for CBWIRE to properly bind to your component and update the DOM. This can be any valid HTML element. Below we are using a DIV element.

```html
<cfoutput>
    <!-- GOOD: single outer element -->
    <div>
        <p>My awesome component</p>
    </div>
</cfoutput>

<cfoutput>
    <!-- BAD: 2 outer elements -->
    <div>
        My awesome component    
    </div>
    <div>
        <p>This won't work.</p>
    </div>
</cfoutput>
```

## Accessing Properties

You can access your [Data Properties](#data-properties) from your template by calling the property name.

```html
<cfscript>
    data = {
        "greeting": "Hello from CBWIRE"
    };
</cfscript>

<cfoutput>
    <div>
        Greeting: #greeting#
    </div>
</cfoutput>
```

You can access your [Computed Properties](/3.x/essentials/computed-properties.md) from your template by calling the property name as a method.

```html
<cfscript>
    computed = {
        "greeting": function() { 
            return "Hello from CBWIRE" 
        }
    };
</cfscript>

<cfoutput>
    <div>
        Greeting: #greeting()#
    </div>
</cfoutput>
```

## Helper Methods

You can access any global helper methods you have defined in your ColdBox application, along with any modules you have installed.

For example, if you've installed the cbi8n module ( an internalization module for ColdBox ), you can access its global helper methods in your template, such as the `$r()` method for displaying text in various languages.

```html
<cfoutput>
    <div>
        #$r( "greeting" )#
    </div>
</cfoutput>
```

## Nesting Components

You can nest components as much as you need by simply calling **wire()** from within a component's template.

```html
<!--- ./wires/ShowPosts.cfm --->
<cfscript>
    // Data properties, actions go here.
</cfscript>

<cfoutput>
    <div>
        <h1>Posts</h1>
        #wire( "AddPostForm" )#
        ...
    </div>
</cfoutput>
```

You can also conditionally render nested components.

```html
<cfscript>
    data = {
        "showForm" : false
    };
</cfscript>

<cfoutput>
    <div>
        <cfif showForm>
            #wire( "MyForm" )#
        </cfif>    
        <button wire:click="$toggle( 'showForm' )">Toggle form</button>
    </div>
</cfoutput>
```


---

# 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://cbwire.ortusbooks.com/3.x/essentials/templates.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
