Skip to content

Commit

Permalink
docs: add section titles and descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
kenjis committed Apr 14, 2024
1 parent 7b45a2b commit 4d88c19
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
18 changes: 17 additions & 1 deletion user_guide_src/source/outgoing/view_decorators.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,36 @@
View Decorators
###############

.. contents::
:local:
:depth: 2

*************************
What are View Decorators?
*************************

View Decorators allow your application to modify the HTML output during the rendering process. This happens just
prior to being cached, and allows you to apply custom functionality to your views.

You can use View Decorators with :doc:`view_renderer` or :doc:`view_parser`.

*******************
Creating Decorators
*******************

Creating Decorator Class
========================

Creating your own view decorators requires creating a new class that implements ``CodeIgniter\View\ViewDecoratorInterface``.
This requires a single method that takes the generated HTML string, performs any modifications on it, and returns
the resulting HTML.

.. literalinclude:: view_decorators/001.php

Once created, the class must be registered in ``app/Config/View.php``:
Registering Decorator Class
===========================

Once created, the class must be registered in **app/Config/View.php**:

.. literalinclude:: view_decorators/002.php

Expand Down
4 changes: 2 additions & 2 deletions user_guide_src/source/outgoing/view_decorators/002.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

class View extends BaseView
{
// ...

public array $decorators = [
'App\Views\Decorators\MyDecorator',
];

// ...
}

0 comments on commit 4d88c19

Please sign in to comment.