wheels generate view
Generate view files for controllers.
Synopsis
wheels generate view [objectName] [name] [template]
wheels g view [objectName] [name] [template]CommandBox Parameter Syntax
Positional parameters:
wheels generate view user show(most common for this command)Named parameters:
objectName=value name=value(e.g.,objectName=user name=show)Flag parameters:
--flagequalsflag=true(e.g.,--forceequalsforce=true)
Recommended: Use positional parameters: wheels generate view user show With template: wheels generate view user show crud/show
Description
The wheels generate view command creates view files for controllers. It can generate individual views using templates or create blank view files.
Arguments
objectName
View path folder (e.g., user)
Required
name
Name of the file to create (e.g., edit)
Required
template
Optional template to use
Options
--force
Overwrite existing code
false
Template Options
Available templates:
crud/_form- Form partial for new/edit viewscrud/edit- Edit form viewcrud/index- List/index viewcrud/new- New form viewcrud/show- Show/detail view
Examples
Basic view (no template)
# Positional
wheels generate view user show
# Named Parameters
wheels g view objectName=user name=showCreates: /views/users/show.cfm with empty content
View with CRUD template
wheels generate view user show crud/showCreates: /views/users/show.cfm using the show template
Edit form with template
wheels generate view user edit crud/editCreates: /views/users/edit.cfm using the edit template
Form partial
wheels generate view user _form crud/_formCreates: /views/users/_form.cfm using the form partial template
Index view
wheels generate view product index crud/indexCreates: /views/products/index.cfm using the index template
Force overwrite existing file
wheels generate view user show --forceOverwrites existing /views/users/show.cfm
Generated Code Examples
Without Template (blank file)
<!--- View file created by wheels generate view --->With CRUD Index Template
<!--- Product Index --->
<cfparam name="products">
<cfoutput>
<h1>Products index</h1>
<p>#linkTo(route="newProduct", text="Create New Product", class="btn btn-default")#</p>
<cfif products.recordcount>
<table class="table">
<thead>
<tr>
<th>ID</th>
<!--- CLI-Appends-thead-Here --->
<th>Actions</th>
</tr>
</thead>
<tbody>
<cfloop query="products">
<tr>
<td>
#id#
</td>
<!--- CLI-Appends-tbody-Here --->
<td>
<div class="btn-group">
#linkTo(route="Product", key=id, text="View", class="btn btn-xs btn-info", encode=false)#
#linkTo(route="editProduct", key=id, text="Edit", class="btn btn-xs btn-primary", encode=false)#
</div>
#buttonTo(route="Product", method="delete", key=id, text="Delete", class="pull-right", inputClass="btn btn-danger btn-xs", encode=false)#
</td>
</tr>
</cfloop>
</tbody>
</table>
<cfelse>
<p>Sorry, there are no Products yet</p>
</cfif>
</cfoutput>
With CRUD New Template
<!--- Product Creation Form --->
<cfparam name="product">
<cfoutput>
<h1>Create New Product</h1>
#errorMessagesFor("product")#
#startFormTag(id="productNewForm", action="create")#
#includePartial("form")#
#submitTag(value="Create Product")#
#endFormTag()#
</cfoutput>With CRUD Show Template
<!--- Product Show --->
<cfparam name="product">
<cfoutput>
<h1>View Product</h1>
<!--- CLI-Appends-Here --->
</cfoutput>With CRUD Form Partial Template
<!--- Product Form Contents --->
<cfoutput>
|FormFields|
<!--- CLI-Appends-Here --->
</cfoutput>Partial Views
Partials Views start with underscore (_form.cfm, _item.cfm):
Naming Convention
Partials start with underscore:
_form.cfm- Form partial_item.cfm- List item partial_sidebar.cfm- Sidebar partial
<!--- In layout or view --->
#includePartial("/shared/header")#
#includePartial("/products/form", product=product)#Best Practices
Keep views simple and focused on presentation
Use partials for reusable components
Move complex logic to helpers or controllers
Follow naming conventions (partials start with _)
Use semantic HTML markup
Common Patterns
Empty State
<cfif products.recordCount>
<!--- Show products --->
<cfelse>
<div class="empty-state">
<h2>No products found</h2>
<p>Get started by adding your first product.</p>
#linkTo(text="Add Product", action="new", class="btn btn-primary")#
</div>
</cfif>Error Display
<cfif product.hasErrors()>
<div class="alert alert-danger">
#errorMessagesFor("product")#
</div>
</cfif>See Also
wheels generate controller - Generate controllers
wheels scaffold - Generate complete CRUD
wheels generate test - Generate view tests
Last updated
Was this helpful?

