Our last important task to make this app functional is to define the custom
template for PhoneDetailView.
External Templates
For large or complex templates, it can be unwieldy to put them inline in the
class, as we’ve done for PhoneCitationView and ControllerView. FOAM allows
you to place templates in external files.
You specify that an external template exists by defining a template object in
your class that provides only its name. Update PhoneDetailView to look like
this:
When a class (PhoneDetailView) has a template with only a name (toHTML)
FOAM will look in the same directory for a file called
PhoneDetailView_toHTML.ft. (.ft is for “FOAM template”.)
Create this file now, and add the following, which was adapted from the
AngularJS Phonecat tutorial. There’s a lot here, but most of it is pretty
straightforward:
There’s quite a lot there, but it’s mostly the same pattern repeated for each
group of specs. A few points of interest:
this.nextID() is a function all Views have, which returns a fresh
identifier they can use as the ID of a DOM element.
We can define new variables and functions in templates, like checkmark.
Once you’ve got this file saved, reload the app and navigate to a phone, and you
should see its information nicely laid out. Clicking a thumbnail image will load
the larger version.
Finished
And that’s the complete app! Hopefully you now have a better feel for the steps
of building a FOAM app, and are ready to start building your own.