For simplicity sake, there is a correlation between the view class name and the template file name. It’s the translation of the name into a path: from to dashboard/index
.
The remaining part is made of multiple file extensions. The first is relative to the format and the latter is for the template engine.
For a given view named Web::Views::Dashboard::Index
, there must be at least one template dashboard/index.[format].[engine]
under the templates directory.
To render a template in other template call render
method with template
option:
If we want to associate a different template to a view, we can use template
.
Our view will look for apps/web/templates/home/index.*
template.
This is a list of the supported engines. They are listed in order of higher precedence, for a given extension. For instance, if is loaded, it will be preferred over ERb to render .erb
templates.
In order to use a different template engine we need to bundle the gem and to use the right file extension.
Templates are located in the default directory templates
, located under an application’s directory apps/web
. If we want to customize this location, we can amend our application’s configuration.