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><!-- wires/greeter.cfm -->
<cfoutput>
<div>
<h1>#greeting#</h1>
<button wire:click="updateGreeting">Update</button>
<cfif timeOfDay() EQ "morning">
<p>Good morning!</p>
<cfelse>
<p>Good day!</p>
</cfif>
</div>
</cfoutput>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:
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:
Be cautious when using event.getCollection() (RC scope) or event.getPrivateCollection() (PRC scope) in templates. CBWIRE fires background requests to /cbwire/update on component re-renders, which may not have access to values set by interceptors or handlers that only run on your primary routes. If you need values from RC or PRC scopes, store them as data properties in your component's onMount() method to ensure they persist across re-renders.
Last updated
Was this helpful?