- 1 Introduction
- 2 Extension Mechanism
- 2.1 Introduction
- 2.2 Add a Module
- 2.3 Extend control
- 2.4 Extend model
- 2.5 Extend view
- 2.6 Extend style sheet and JS
- 2.7 Extend language and configuration
- 2.8 Add Class Library
- 3 API Mechanism
- 4 Command Line
Extend view
- 2018-07-16 09:44:51
- tengfei
- 7574
- 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.