CBWIRE
InstallSource CodeIssuesSupport
v3.x
v3.x
  • Introduction
  • Getting Started
  • Configuration
  • How It Works
  • Release History
    • What's New With 3.2
    • What's New With 3.1
    • What's New With 3.0
    • What's New With 2.2
    • What's New With 2.1
    • What's New With 2.0
  • Examples
    • Contact Form
    • Multi-select Input
    • File Upload
  • Resources
  • The Essentials
    • Components
    • Templates
    • Data Properties
    • Computed Properties
    • Actions
    • Events
    • Lifecycle Methods
    • JavaScript
    • Testing
  • Wire Features
    • Validation
    • File Uploads
    • Query String
    • Redirecting
    • WireBox
  • Template Features
    • Directives
    • Loading States
    • Polling
    • Prefetching
    • Offline State
    • Defer Loading
    • Dirty State
  • Integrations
    • ContentBox CMS
    • SPAs with Turbo
    • AlpineJS
Powered by GitBook
On this page
  • Outer Element
  • Accessing Properties
  • Helper Methods
  • Nesting Components
  1. The Essentials

Templates

The HTML that makes up your components.

PreviousComponentsNextData Properties

Last updated 1 year ago

Templates are the HTML section of your and consist of any valid CFML tags. This includes <cfif>, <cfloop>, etc.

<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.

<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

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

<cfoutput>
    <div>
        Greeting: #greeting#
    </div>
</cfoutput>
<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.

<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.

<!--- ./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.

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

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

You can access your from your template by calling the property name.

You can access your from your template by calling the property name as a method.

Components
Computed Properties
Data Properties