Extension Of View

2022-05-09 15:53:02
Kelsea
1736
Last edited by Hongyan on 2022-05-10 17:14:30
Share links

Extension Of View

There are two ways to extend the view file, one is to overwrite it completely and the second is to extend it through the hook mechanism.

1. Overwrite it completely

The override of the view file can be redefined by a complete override. For example, I'm going to extend the page Create in the Bug module, and the original view file is stored in module/bug/view/create.html.php. The only thing I need to do is copy the create.html.php to extension/custom/bug/ext/view/create.html.php, and then modify the page.


It should be noted that when copying and pasting, the including path needs to be changed accordingly.

2. Extending through the hook mechanism

The first method is simple and intuitive, but it has its disadvantage that the code cannot be reused. Assuming that there are changes in later versions, the view files of the old version may not be compatible with the programs of the new version. So you can consider code reuse through hook scripts. The naming convention of hook script is the method name. extension.html.hook.php. The hook file will be loaded after the entire template is loaded, and the corresponding php code or js code can be executed in it. This provides a mechanism to dynamically modify page elements through js, so as to achieve complete control over page elements.

 

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

$('#topbar').css('color', 'red'); 

Through the above js code, the red display of the top navigation bar is realized.

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