Command Line Tools
Template System
Template System
Section titled “Template System”The Wheels CLI uses a powerful template system for code generation that allows you to customize the output to match your project’s coding standards and conventions.
Overview
Section titled “Overview”The template system enables:
- Consistent Code Generation - All generated code follows the same patterns
- Project Customization - Override templates to match your project’s needs
- Markup Control - Customize HTML, CSS frameworks, and JavaScript patterns
- Convention Enforcement - Ensure generated code follows your team’s standards
How It Works
Section titled “How It Works”Template Resolution
Section titled “Template Resolution”When the CLI generates code, it looks for templates in this order:
-
Application Templates (
/app/snippets/)- Project-specific templates that override defaults
- Allows per-project customization
-
CLI Templates (
/cli/templates/)- Default templates shipped with the CLI
- Fallback when no app template exists
This hierarchy ensures that your customizations always take precedence over the defaults.
Template Processing
Section titled “Template Processing”Templates are processed through these steps:
- Template Loading - The appropriate template file is loaded
- Placeholder Replacement - Variables and placeholders are replaced with actual values
- Code Generation - The processed content is written to the destination file
Template Override System
Section titled “Template Override System”Purpose
Section titled “Purpose”The template override system allows you to:
- Customize generated markup to match your CSS framework (Bootstrap, Tailwind, etc.)
- Add project-specific code patterns and conventions
- Include custom comments, documentation, or boilerplate
- Modify the structure of generated files
Creating Custom Templates
Section titled “Creating Custom Templates”To override a CLI template:
-
Identify the template you want to customize
Terminal window # View available templatesls /path/to/wheels/cli/templates/ -
Create the directory structure in your app
Terminal window mkdir -p app/snippets/crud -
Copy the template to your app
Terminal window cp /path/to/wheels/cli/templates/crud/_form.txt app/snippets/crud/ -
Modify the template to match your needs
Terminal window # Edit with your preferred editorcode app/snippets/crud/_form.txt
Example: Customizing Form Templates
Section titled “Example: Customizing Form Templates”Default form template (/cli/templates/crud/_form.txt):
<!--- |ObjectNameSingularC| Form Contents ---><cfoutput>|FormFields|<!--- CLI-Appends-Here ---></cfoutput>Custom Bootstrap 5 template (/app/snippets/crud/_form.txt):
<!--- |ObjectNameSingularC| Form ---><cfoutput><div class="card"> <div class="card-body"> #errorMessagesFor("|ObjectNameSingular|")#
<div class="form-fields"> |FormFields| </div>
<div class="form-actions mt-3"> #submitTag(value="Save", class="btn btn-primary")# #linkTo(text="Cancel", action="index", class="btn btn-secondary")# </div> </div></div><!--- CLI-Appends-Here ---></cfoutput>Available Templates
Section titled “Available Templates”Model Templates
Section titled “Model Templates”ModelContent.txt- Base model structuredbmigrate/*.txt- Migration templates
Controller Templates
Section titled “Controller Templates”ControllerContent.txt- Base controller structureApiControllerContent.txt- API controller structure
View Templates
Section titled “View Templates”ViewContent.txt- Generic view templatecrud/index.txt- List/index viewcrud/show.txt- Show single recordcrud/new.txt- New record formcrud/edit.txt- Edit record formcrud/_form.txt- Form partial
Test Templates
Section titled “Test Templates”tests/model.txt- Model test structuretests/controller.txt- Controller test structuretests/view.txt- View test structure
Configuration Templates
Section titled “Configuration Templates”ConfigAppContent.txt- Application configurationConfigRoutes.txt- Routes configurationConfigDataSourceH2Content.txt- H2 database configuration
Template Variables
Section titled “Template Variables”Object Name Variables
Section titled “Object Name Variables”|ObjectNameSingular|- Lowercase singular (e.g., “product”)|ObjectNamePlural|- Lowercase plural (e.g., “products”)|ObjectNameSingularC|- Capitalized singular (e.g., “Product”)|ObjectNamePluralC|- Capitalized plural (e.g., “Products”)
Dynamic Content Variables
Section titled “Dynamic Content Variables”|FormFields|- Generated form fields based on properties|Actions|- Generated controller actions{{belongsTo}}- Belongs-to relationship code{{hasMany}}- Has-many relationship code{{validations}}- Model validation code
Marker Comments
Section titled “Marker Comments”<!--- CLI-Appends-Here --->- Marker for future CLI additions<!--- CLI-Appends-thead-Here --->- Table header additions<!--- CLI-Appends-tbody-Here --->- Table body additions
Best Practices
Section titled “Best Practices”1. Version Control Templates
Section titled “1. Version Control Templates”Always commit your custom templates to version control:
git add app/snippets/git commit -m "Add custom templates for Bootstrap 5"2. Document Customizations
Section titled “2. Document Customizations”Add comments explaining your customizations:
<!--- Custom template for Bootstrap 5 forms - Uses card layout - Includes form validation styles - Adds cancel button--->3. Maintain Placeholders
Section titled “3. Maintain Placeholders”Keep important placeholders and markers:
- Always include
<!--- CLI-Appends-Here --->for future additions - Preserve variable placeholders you might need later
4. Test Generated Code
Section titled “4. Test Generated Code”After customizing templates:
# Generate a test scaffoldwheels scaffold test properties=name:string
# Verify the output matches expectations# Delete test files when done5. Share Team Templates
Section titled “5. Share Team Templates”Create a shared template repository for team consistency:
# Create template packagecd app/snippetstar -czf project-templates.tar.gz *
# Share with teamAdvanced Customization
Section titled “Advanced Customization”Conditional Generation
Section titled “Conditional Generation”Use CFML logic in templates:
<cfif arrayLen(properties) GT 5> <!--- Use compact layout for many fields ---> <div class="row"> |FormFields| </div><cfelse> <!--- Standard layout ---> |FormFields|</cfif>Custom Placeholders
Section titled “Custom Placeholders”Add your own placeholders in templates:
<!--- |ProjectName| - |GeneratedDate| ---><!--- Version: |Version| --->Then handle them in your custom generator commands.
Framework-Specific Templates
Section titled “Framework-Specific Templates”Create template sets for different CSS frameworks:
app/snippets/├── bootstrap5/│ └── crud/│ ├── _form.txt│ └── index.txt├── tailwind/│ └── crud/│ ├── _form.txt│ └── index.txt└── crud/ # Current active templates ├── _form.txt └── index.txtSwitch between them by copying to the active directory.
Troubleshooting
Section titled “Troubleshooting”Templates Not Being Used
Section titled “Templates Not Being Used”- Check file paths - ensure templates are in
/app/snippets/ - Verify file names match exactly (case-sensitive)
- Reload CommandBox if changes aren’t picked up:
box reload
Generated Code Has Errors
Section titled “Generated Code Has Errors”- Check for syntax errors in your template
- Ensure all placeholders are properly closed
- Test with a simple template first
Placeholders Not Replaced
Section titled “Placeholders Not Replaced”- Verify placeholder syntax is exact
- Check that the data is being passed to the template
- Some placeholders only work in specific template types
See Also
Section titled “See Also”- Creating Commands - Build custom generators
- Service Architecture - Understand the template service
- wheels scaffold - Main scaffold documentation