Modules are packages that can be plugged into an application. They allow sharing of controllers, views, assets, and other code between multiple Revel applications or from third-party sources.
A module should have the same layout as a Revel application’s layout. The “hosting” application will merge it in as follows:
- Any templates in
module/app/viewswill be added to the Template Loader search path
- Any controllers in
module/app/controllerswill be treated as if they were in your application
- The assets are made available, via a route action of the form
- Routes can be included in your application with the route line of
module:modulename- see routing
Enabling a module
In order to add a module to your app, add a line to
You can add an ordering method by insert a sortable string in between the word module and the name of the module like the following. This allows you to specify which order the views should be loaded, so your application will always be the first, then the order of the modules and finally the default views in Revel.
An empty import path disables the module:
For example, to enable the test runner module:
Routing a module
Building a module
It’s a good idea to make sure all your views are in their own namespace
so that they will not conflict with other applications that your module is
imported into. If you have a module called Reservation, it would be a good
idea to have your view path look like
. This means that your controller needs to call
Render so that the correct view path is chosen.