Guide
Setting Up a Basic Alloy MVC Project in Appcelerator Titanium
Learn how to scaffold an Alloy‑based Titanium project, add a model‑view‑controller trio, and verify live data binding between model properties and UI labels.
Published by Tasadduq Burney
24 Mar 2026, 14:39 UTC
3 min84.4K views0

Desired outcome
Create a new Appcelerator Titanium project that uses the Alloy MVC framework, add a simple controller, view, and model, and verify that changes to the model update the UI.
Prerequisites
- Titanium CLI installed (version ≥ 9.0.0).
- Node.js and npm available.
- Basic familiarity with command‑line tools.
- Write permission in the target workspace directory.
Procedure
- Initialize the project
Run the following command in your workspace:
Replacetitanium create --id com.example. --alloy<project-name>with a lowercase identifier (e.g.,todoapp). The--alloyflag tells the CLI to scaffold an Alloy‑based app. - Navigate into the project
cd - Verify the Alloy directory structure
The command should have created:
If any of these folders are missing, re‑run the create command withapp/ └── alloy/ ├── controllers/ ├── models/ ├── styles/ └── views/--alloyor check the CLI version. - Create a model
Generate a model file nameditem.js:
This createsalloy generate model itemapp/alloy/models/item.jsand an emptyapp/alloy/models/item.xml(optional). - Create a controller and view
Generate a controller calledmain:
This yieldsalloy generate controller mainapp/alloy/controllers/main.jsandapp/alloy/views/main.xml. - Edit the view to bind a model attribute
Openapp/alloy/views/main.xmland replace its content with:
The expression<Alloy> <Window class='container'> <Label id='itemLabel' text='{item.title}' /> </Window> </Alloy>{item.title}binds the Label’s text to thetitleattribute of a model nameditem. - Wire the model in the controller
Editapp/alloy/controllers/main.js:var Item = Alloy.createModel('item'); Item.set({title: 'Initial value'}); $.itemLabel.text = Item.get('title'); // initial sync // Expose the model for later updates exports.model = Item; - Set the controller as the entry point
Openapp/alloy/config.json(create if missing) and ensure:
Then edit{ "global": {} }app.js(generated by the CLI) to load the main controller:var main = Alloy.createController('main'); main.getView().open(); - Build and run
For iOS simulator (requires macOS and Xcode):
For Android emulator:titanium build --platform ios --target simulator
The CLI will compile the Alloy assets into native Titanium code and launch the app.titanium build --platform android --target emulator - Check the result
You should see a window displaying a label with the text “Initial value”. To verify data binding, change the model value at runtime (e.g., via the console):
The label should update automatically without manual UI code.Alloy.Controllers.main.model.set({title: 'Updated value'});
Expected checks
- The
app/alloyfolder containscontrollers,models,views, andstylessubfolders. - The build completes without errors; the simulator/emulator launches.
- The label’s text changes when the model’s
titleattribute is modified.
Recovery options (rollback)
If the generated files cause conflicts or you wish to start over:
- Remove the project directory:
rm -rf(ensure you have no unsaved work elsewhere). - Re‑run the
titanium createcommand with the--alloyflag.
Because the operation only creates files, deleting the directory restores the previous state.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.