Extend view

2018-07-16 09:44:51
Last edited by tengfei on 2019-01-08 09:43:20

There are two ways to extend view files, 

  • override completely, and 
  • extend by a hook.

1. Override

To override view files can be redefined by complete overriding. For example, extend the Create page of the Bug module. The original view file is saved in module/bug/view/create.html.php. If you want to extend it, just copy the create.html.php to module/bug/ext/view/create.html.php, and then modify the page.

Note: When copying the file, change the path accordingly.

2. Hook

The first way is simple and intuitive, but it has a disadvantage which is that the code cannot be reused. If there is a new version, the old version of the view file and the new might be incompatible with it. Therefore, a hook is used to reuse the code. The naming rule of a hook is extension.html.hook.php. The hook file will be loaded after the template is loaded, and the corresponding PHP code or JS code will be executed. It is to change page elements through JS in a dynamic way, so as to control page elements completely.

For example, misc/ext/view/getsid.color.html.hook.php

$('#topbar').css('color', 'red');
This JS code above is to highlight the top navigation bar in red.

Write a Comment
Comment will be posted after it is reviewed.