File tree Expand file tree Collapse file tree
user_guide_src/source/outgoing Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22View Decorators
33###############
44
5+ .. contents ::
6+ :local:
7+ :depth: 2
8+
9+ *************************
10+ What are View Decorators?
11+ *************************
12+
513View Decorators allow your application to modify the HTML output during the rendering process. This happens just
614prior to being cached, and allows you to apply custom functionality to your views.
715
16+ You can use View Decorators with :doc: `view_renderer ` or :doc: `view_parser `.
17+
818*******************
919Creating Decorators
1020*******************
1121
22+ Creating Decorator Class
23+ ========================
24+
1225Creating your own view decorators requires creating a new class that implements ``CodeIgniter\View\ViewDecoratorInterface ``.
1326This requires a single method that takes the generated HTML string, performs any modifications on it, and returns
1427the resulting HTML.
1528
1629.. literalinclude :: view_decorators/001.php
1730
18- Once created, the class must be registered in ``app/Config/View.php ``:
31+ Registering Decorator Class
32+ ===========================
33+
34+ Once created, the class must be registered in **app/Config/View.php **:
1935
2036.. literalinclude :: view_decorators/002.php
2137
Original file line number Diff line number Diff line change 66
77class View extends BaseView
88{
9+ // ...
10+
911 public array $ decorators = [
1012 'App\Views\Decorators\MyDecorator ' ,
1113 ];
12-
13- // ...
1414}
You can’t perform that action at this time.
0 commit comments