Skip to content

Commit 5abf826

Browse files
authored
Merge pull request #5660 from kenjis/fix-docs-view_renderer.rst
docs: improve view_renderer.rst
2 parents 35a8bc5 + 388adf1 commit 5abf826

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

user_guide_src/source/outgoing/view_renderer.rst

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ to you to process the array appropriately in your PHP code.
4848
Method Chaining
4949
===============
5050

51-
The `setVar()` and `setData()` methods are chainable, allowing you to combine a
51+
The ``setVar()`` and ``setData()`` methods are chainable, allowing you to combine a
5252
number of different calls together in a chain::
5353

5454
$view->setVar('one', $one)
@@ -62,7 +62,7 @@ When you pass data to the ``setVar()`` and ``setData()`` functions you have the
6262
against cross-site scripting attacks. As the last parameter in either method, you can pass the desired context to
6363
escape the data for. See below for context descriptions.
6464

65-
If you don't want the data to be escaped, you can pass `null` or `raw` as the final parameter to each function::
65+
If you don't want the data to be escaped, you can pass ``null`` or ``'raw'`` as the final parameter to each function::
6666

6767
$view->setVar('one', $one, 'raw');
6868

@@ -78,7 +78,7 @@ Escaping Contexts
7878
By default, the ``esc()`` and, in turn, the ``setVar()`` and ``setData()`` functions assume that the data you want to
7979
escape is intended to be used within standard HTML. However, if the data is intended for use in Javascript, CSS,
8080
or in an href attribute, you would need different escaping rules to be effective. You can pass in the name of the
81-
context as the second parameter. Valid contexts are 'html', 'js', 'css', 'url', and 'attr'::
81+
context as the second parameter. Valid contexts are ``'html'``, ``'js'``, ``'css'``, ``'url'``, and ``'attr'``::
8282

8383
<a href="<?= esc($url, 'url') ?>" data-foo="<?= esc($bar, 'attr') ?>">Some Link</a>
8484

@@ -98,8 +98,7 @@ View Renderer Options
9898
Several options can be passed to the ``render()`` or ``renderString()`` methods:
9999

100100
- ``cache`` - the time in seconds, to save a view's results; ignored for renderString()
101-
- ``cache_name`` - the ID used to save/retrieve a cached view result; defaults to the viewpath;
102-
ignored for renderString()
101+
- ``cache_name`` - the ID used to save/retrieve a cached view result; defaults to the viewpath; ignored for ``renderString()``
103102
- ``saveData`` - true if the view data parameters should be retained for subsequent calls
104103

105104
.. note:: ``saveData`` as defined by the interface must be a boolean, but implementing
@@ -110,7 +109,7 @@ Class Reference
110109

111110
.. php:class:: CodeIgniter\\View\\View
112111
113-
.. php:method:: render($view[, $options[, $saveData=false]])
112+
.. php:method:: render($view[, $options[, $saveData = false]])
114113
:noindex:
115114

116115
:param string $view: File name of the view source
@@ -123,7 +122,7 @@ Class Reference
123122

124123
echo $view->render('myview');
125124

126-
.. php:method:: renderString($view[, $options[, $saveData=false]])
125+
.. php:method:: renderString($view[, $options[, $saveData = false]])
127126
:noindex:
128127

129128
:param string $view: Contents of the view to render, for instance content retrieved from a database
@@ -136,12 +135,12 @@ Class Reference
136135

137136
echo $view->renderString('<div>My Sharona</div>');
138137

139-
This could be used for displaying content that might have been stored in a database,
138+
.. warning:: This could be used for displaying content that might have been stored in a database,
140139
but you need to be aware that this is a potential security vulnerability,
141140
and that you **must** validate any such data, and probably escape it
142141
appropriately!
143142

144-
.. php:method:: setData([$data[, $context=null]])
143+
.. php:method:: setData([$data[, $context = null]])
145144
:noindex:
146145

147146
:param array $data: Array of view data strings, as key/value pairs
@@ -153,13 +152,13 @@ Class Reference
153152

154153
$view->setData(['name'=>'George', 'position'=>'Boss']);
155154

156-
Supported escape contexts: html, css, js, url, or attr or raw.
157-
If 'raw', no escaping will happen.
155+
Supported escape contexts: ``html``, ``css``, ``js``, ``url``, or ``attr`` or ``raw``.
156+
If ``'raw'``, no escaping will happen.
158157

159158
Each call adds to the array of data that the object is accumulating,
160159
until the view is rendered.
161160

162-
.. php:method:: setVar($name[, $value=null[, $context=null]])
161+
.. php:method:: setVar($name[, $value = null[, $context = null]])
163162
:noindex:
164163

165164
:param string $name: Name of the view data variable
@@ -172,8 +171,8 @@ Class Reference
172171

173172
$view->setVar('name','Joe','html');
174173

175-
Supported escape contexts: html, css, js, url, attr or raw.
176-
If 'raw', no escaping will happen.
174+
Supported escape contexts: ``html``, ``css``, ``js``, ``url``, ``attr`` or ``raw``.
175+
If ``'raw'``, no escaping will happen.
177176

178177
If you use the a view data variable that you have previously used
179178
for this object, the new value will replace the existing one.

0 commit comments

Comments
 (0)