Templates

Templates define your component's HTML presentation layer using standard HTML/CFML tags. They're dynamic, reactive views that access your component's data properties and methods to create interactive user experiences.

CBWIRE automatically looks for template files with the same name as your component. Templates can use BoxLang tags like <bx:if>, <bx:loop>, and <bx:output> or CFML tags like <cfif>, <cfloop>, and <cfoutput> alongside wire directives for reactive behavior.

<!-- wires/greeter.bxm -->
<bx:output>
<div>
    <h1>#greeting#</h1>
    <button wire:click="updateGreeting">Update</button>
    
    <bx:if timeOfDay() EQ "morning">
        <p>Good morning!</p>
    <bx:else>
        <p>Good day!</p>
    </bx:if>
</div>
</bx:output>

File Structure

CBWIRE uses automatic file matching for components and templates:

./wires/Counter.bx     <!-- BoxLang class -->
./wires/Counter.cfc    <!-- CFML component -->
./wires/counter.bxm    <!-- BoxLang template -->
./wires/counter.cfm    <!-- CFML template -->

Template Requirements

Templates must have a single outer element for proper DOM binding:

Data Properties

Access component data properties directly by name:

Computed Properties

Define computed properties with the computed annotation and call them as methods:

Computed properties are cached and only executed when first called or when their dependencies change. See Computed Properties for details.

Explicit Templates

Override default template location using the onRender() method:

Helper Methods

Access global helper methods from installed ColdBox modules:

ColdBox Event Object

Access the ColdBox event object (request context) directly in your templates to use helpful methods like event.buildLink() for generating URLs:

Last updated

Was this helpful?