alloy-howtos
Titanium Alloy How-tos
Practical guide for Alloy MVC projects in the Titanium SDK.
Project detection
:::info Auto-detects Alloy projects This skill checks for Alloy projects when invoked and provides CLI and configuration guidance.
Detection is automatic. No manual command is needed.
Alloy project indicators:
app/folder with Alloy structurealloy.jmkorconfig.jsonfiles
Behavior based on detection:
- Alloy detected -> Provide Alloy CLI command guidance, configuration file help, Alloy-specific troubleshooting
- Not detected -> Explain this skill is for Alloy projects only and suggest Alloy guides if the user wants to migrate :::
Quick reference
| Topic | Reference |
|---|---|
| Best Practices & Naming Conventions | best_practices.md |
| CLI Commands (new, generate, compile) | cli_reference.md |
| Configuration Files (alloy.jmk, config.json) | config_files.md |
| Custom XML Tags & Reusable Components | custom_tags.md |
| Debugging & Common Errors | debugging_troubleshooting.md |
| Code Samples & Conditionals | samples.md |
Key practices
Naming conventions
- Never use double underscore prefixes (
__foo) - reserved for Alloy - Never use JavaScript reserved words as IDs
Global events - use Backbone.Events
Avoid Ti.App.fireEvent / Ti.App.addEventListener. It can cause memory leaks and poor performance.
Use the Backbone.Events pattern:
// In alloy.js
Alloy.Events = _.clone(Backbone.Events);
// Listener
Alloy.Events.on('updateMainUI', refreshData);
// Clean up on close
$.controller.addEventListener('close', () => {
Alloy.Events.off('updateMainUI');
});
// Trigger
Alloy.Events.trigger('updateMainUI');
Global variables in non-controller files
Always require Alloy modules:
const Alloy = require('alloy');
const Backbone = require('alloy/backbone');
const _ = require('alloy/underscore')._;
Conditional views
Use if attributes in XML for conditional rendering (evaluated before render):
<Alloy>
<Window>
<View if="Alloy.Globals.isLoggedIn()" id="notLoggedIn">
<Label text="Not logged in" />
</View>
<View if="!Alloy.Globals.isLoggedIn()" id="loggedIn">
<Label text="Logged in" />
</View>
</Window>
</Alloy>
Conditional TSS styles:
"#info[if=Alloy.Globals.isIos7Plus]": {
font: { textStyle: Ti.UI.TEXT_STYLE_FOOTNOTE }
}
Data-binding conditionals:
<TableViewRow if="$model.shouldShowCommentRow()">
Common error solutions
| Error | Solution |
|---|---|
No app.js found |
Run alloy compile --config platform=<platform> |
| Android assets not showing | Use absolute paths (prepend /) |
Alloy is not defined (non-controller) |
Add const Alloy = require('alloy'); |
iOS invalid method passed to UIModule |
Creating Android-only object - use platform attribute |
CLI quick reference
# New project
alloy new [path] [template]
# Generate components
alloy generate controller <name>
alloy generate model <name> <adapter> <schema>
alloy generate style --all
# Compile
alloy compile [--config platform=android,deploytype=test]
# Extract i18n strings
alloy extract-i18n en --apply
# Copy/move/remove controllers
alloy copy <old> <new>
alloy move <old> <new>
alloy remove <name>
Configuration files priority
config.json precedence: os:ios > env:production > global
Access at runtime: Alloy.CFG.yourKey
Custom XML tags
Create reusable components without widgets. Drop a file in app/lib/:
app/lib/checkbox.js
exports.createCheckBox = args => {
const wrapper = Ti.UI.createView({ layout: "horizontal", checked: false });
const box = Ti.UI.createView({ width: 15, height: 15, borderWidth: 1 });
// ... build component, return Ti.UI.* object
return wrapper;
};
view.xml
<CheckBox module="checkbox" id="terms" caption="I agree" onChange="onCheck" />
Key: the module attribute points to the file in app/lib/ (without .js). The function must be create<TagName>.
See custom_tags.md for complete examples.
Resources
references/
Reference docs by topic:
- best_practices.md - Coding standards, naming conventions, global events patterns
- cli_reference.md - All CLI commands with options and model schema format
- config_files.md - alloy.jmk tasks, config.json structure, widget.json format
- custom_tags.md - Creating reusable custom XML tags without widgets
- debugging_troubleshooting.md - Common errors with solutions
- samples.md - Controller examples, conditional views, data-binding patterns
Related skills
For tasks beyond Alloy CLI and configuration, use these related skills:
| Task | Use This Skill |
|---|---|
| Modern architecture, services, patterns | ti-expert |
| Alloy MVC concepts, models, data binding | alloy-guides |
| SDK config, Hyperloop, app distribution | ti-guides |
More from maccesar/titools
ti-ui
Titanium SDK UI/UX patterns and components expert. Use when working with, reviewing, analyzing, or examining Titanium layouts, ListView/TableView performance optimization, event handling and bubbling, gestures (swipe, pinch), animations, accessibility (VoiceOver/TalkBack), orientation changes, custom fonts/icons, app icons/splash screens, or platform-specific UI (Action Bar, Navigation Bar).
4purgetss
Titanium PurgeTSS utility-first styling toolkit. Use when styling, reviewing, analyzing, or examining Titanium UI with utility classes, configuring config.cjs, creating dynamic components with $.UI.create(), building animations, using grid layouts, setting up icon fonts, or working with TSS styles. Never suggest other CSS framework classes - verify in class-index.md first.
4ti-guides
Titanium SDK official fundamentals and configuration guide. Use when working with, reviewing, analyzing, or examining Titanium projects, Hyperloop native access, app distribution (App Store/Google Play), tiapp.xml configuration, CLI commands, memory management, bridge optimization, CommonJS modules, SQLite transactions, or coding standards. Applies to both Alloy and Classic projects.
4ti-howtos
Titanium SDK native feature integration guide. Use when implementing, reviewing, analyzing, or examining Titanium location services, maps (Google Maps v2, Map Kit), push notifications (APNs, FCM), camera/gallery, media APIs, SQLite databases, HTTPClient networking, WKWebView, Android Intents, background services, iOS Keychain/iCloud, WatchKit/Siri integration, or CI/CD with Fastlane and Appium.
4ti-expert
Titanium SDK architecture and implementation expert. Use when designing, reviewing, analyzing, or examining Titanium project structure (Alloy or Classic), creating controllers/views/services, choosing models vs collections, implementing communication patterns, handling memory cleanup, testing, auditing code, or migrating legacy apps. Automatically identifies project type.
4alloy-guides
Titanium Alloy MVC official framework reference. Use when working with, reviewing, analyzing, or examining Alloy models, views, controllers, Backbone.js data binding, TSS styling, widgets, Alloy CLI, sync adapters, migrations, or MVC compilation. Explains how Backbone.js models and collections work in Alloy.
4