Understand how the view file is chosen is fundamental if you want mastering frontend customization. In the standard frontend flow the requested url is processed by BEdita to load a section or a content by nickname then it renders the view file named section.tpl located in app/views/pages folder. This view uses the BeFrontHelper::chooseTemplate() method to determine which tempate file has to be included following the schema below:

1. Check frontendMap currentContent nickname

First of all the chooseTemplate() method checks if you have configured the file app/config/mapping.cfg.php to map nicknames or ids to views. If so and if the page points to a content nickname (located in view array $section['currentContent']) mapped then the view specified is searched and eventually used.

Example: app/config/mapping.cfg.php file contains

$config["frontendMap"] = array(
    "example-one" => "sample_template"
);

url: http://www.example.com/example-one where "example-one" is the nickname of a content
view file searched: app/views/pages/sample_template.tpl

The same view is searched if browser points to http://www.example.com/demo/example-one where demo is the nickame of the parent section of example-one.
If view file doesn't exist then it goes on to the next step.

2. Check frontendMap section nickname

If first check fails then the method checks if the current section is mapped in mapping.cfg.php and eventually uses it.

Example: app/config/mapping.cfg.php file contains

$config["frontendMap"] = array(
    "demo" => "demo_template"
);

url: http://www.example.com/demo/example-one
view file searched: app/views/pages/demo_template.tpl

3. View with same name as currentContent nickname

If point 2 fails, then the method try to search a view named as current content nickname.

Example:

url: http://www.example.com/demo/example-one where "example-one" is the nickname of a content.

If it's present a view file named example-one.tpl in app/views/pages folder then it will be used.

4. View with same name as section nickname

Successive check is the same of point 3 but with section nickname instead of content nickname. So if view file with the same name as the section nickname is found in app/views/pages folder then it's used.

5. View with same name as parent sections nickname

if point 4 fails the next step is to check the presence of a view file named as one of the parent section of current section using the $section['pathSection'] array. First view file

6. Object type template name

The last check is done with object type of current content. A view file named as the object type is searched. For example, if you create an event.tpl file in app/views/pages then it is used every time a BEdita object of type event is loaded as a request of an url.

7. Default fallback

If none of the previous checks is satisfied then the fallback mode selects the view file app/views/pages/generic_section.tpl