Skip to content

Commit

Permalink
Update docs for view parser plugins. Closes #1997
Browse files Browse the repository at this point in the history
  • Loading branch information
lonnieezell committed May 15, 2019
1 parent 6713500 commit 3319a8d
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion user_guide_src/source/outgoing/view_parser.rst
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ callable::
PHP Native functions as Filters
-------------------------------

You can easily use native php function as filters by editing **app/Config/View.php** and adding new entries to the
You can use native php function as filters by editing **app/Config/View.php** and adding new entries to the
``$filters`` array.Each key is the name of the native PHP function is called by in the view, and its value is any valid native PHP
function prefixed with::

Expand Down Expand Up @@ -543,6 +543,22 @@ used within the template file. The value is any valid PHP callable, including st
},
];

Any closures that are being used must be defined in the config file's constructor::

class View extends \CodeIgniter\Config\View
{
public $plugins = [];

public function __construct()
{
$this->plugins['bar'] = function(array $params=[]) {
return $params[0] ?? '';
};

parent::__construct();
}
}

If the callable is on its own, it is treated as a single tag, not a open/close one. It will be replaced by
the return value from the plugin::

Expand Down

0 comments on commit 3319a8d

Please sign in to comment.