Skip to content

Commit ee48a4c

Browse files
authored
Merge pull request #5479 from kenjis/fix-docs-view_parser.rst
docs: improve view_parser.rst
2 parents 621d969 + c9af04c commit ee48a4c

1 file changed

Lines changed: 84 additions & 84 deletions

File tree

user_guide_src/source/outgoing/view_parser.rst

Lines changed: 84 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ can instantiate it directly::
5353
$parser = new \CodeIgniter\View\Parser();
5454

5555
Then you can use any of the three standard rendering methods that it provides:
56-
**render(viewpath, options, save)**, **setVar(name, value, context)** and
57-
**setData(data, context)**. You will also be able to specify delimiters directly,
58-
through the **setDelimiters(left, right)** method.
56+
``render(viewpath, options, save)``, ``setVar(name, value, context)`` and
57+
``setData(data, context)``. You will also be able to specify delimiters directly,
58+
through the ``setDelimiters(left, right)`` method.
5959

6060
Using the ``Parser``, your view templates are processed only by the Parser
6161
itself, and not like a conventional view PHP script. PHP code in such a script
@@ -221,12 +221,12 @@ method::
221221
->render('blog_template');
222222

223223
If the array you are trying to loop over contains objects instead of arrays,
224-
the parser will first look for an ``asArray`` method on the object. If it exists,
224+
the parser will first look for an ``asArray()`` method on the object. If it exists,
225225
that method will be called and the resulting array is then looped over just as
226-
described above. If no ``asArray`` method exists, the object will be cast as
226+
described above. If no ``asArray()`` method exists, the object will be cast as
227227
an array and its public properties will be made available to the Parser.
228228

229-
This is especially useful with the Entity classes, which has an asArray method
229+
This is especially useful with the Entity classes, which has an ``asArray()`` method
230230
that returns all public and protected properties (minus the _options property) and
231231
makes them available to the Parser.
232232

@@ -262,8 +262,8 @@ A **blog_template.php** that might work for the above::
262262
</div>
263263
{/blog_entry}
264264

265-
If you would like the other pseudo-variables accessible inside the "blog_entry"
266-
scope, then make sure that the "cascadeData" option is set to true.
265+
If you would like the other pseudo-variables accessible inside the ``blog_entry``
266+
scope, then make sure that the ``cascadeData`` option is set to true.
267267

268268
Comments
269269
========
@@ -356,15 +356,15 @@ of the comparison operators you would normally, like ``==``, ``===``, ``!==``, `
356356
<h1>Welcome, User</h1>
357357
{endif}
358358

359-
.. note:: In the background, conditionals are parsed using an **eval()**, so you must ensure that you take
359+
.. warning:: In the background, conditionals are parsed using an ``eval()``, so you must ensure that you take
360360
care with the user data that is used within conditionals, or you could open your application up to security risks.
361361

362362
Escaping Data
363363
=============
364364

365-
By default, all variable substitution is escaped to help prevent XSS attacks on your pages. CodeIgniter's ``esc`` method
366-
supports several different contexts, like general **html**, when it's in an HTML **attr**, in **css**, etc. If nothing
367-
else is specified, the data will be assumed to be in an HTML context. You can specify the context used by using the **esc**
365+
By default, all variable substitution is escaped to help prevent XSS attacks on your pages. CodeIgniter's ``esc()`` method
366+
supports several different contexts, like general ``html``, when it's in an HTML ``attr``, in ``css``, etc. If nothing
367+
else is specified, the data will be assumed to be in an HTML context. You can specify the context used by using the ``esc()``
368368
filter::
369369

370370
{ user_styles | esc(css) }
@@ -402,66 +402,65 @@ Provided Filters
402402

403403
The following filters are available when using the parser:
404404

405-
+---------------+---------------------+--------------------------------------------------------------+-------------------------------------+
406-
+ **Filter** + **Arguments** + **Description** + **Example** +
407-
+---------------+---------------------+--------------------------------------------------------------+-------------------------------------+
408-
+ abs + + Displays the absolute value of a number. + { v|abs } +
409-
+---------------+---------------------+--------------------------------------------------------------+-------------------------------------+
410-
+ capitalize + + Displays the string in sentence case: all lowercase + { v|capitalize} +
411-
+ + + with firstletter capitalized. + +
412-
+---------------+---------------------+--------------------------------------------------------------+-------------------------------------+
413-
+ date + format (Y-m-d) + A PHP **date**-compatible formatting string. + { v|date(Y-m-d) } +
414-
+---------------+---------------------+--------------------------------------------------------------+-------------------------------------+
415-
+ date_modify + value to add + A **strtotime** compatible string to modify the date, + { v|date_modify(+1 day) } +
416-
+ + / subtract + like ``+5 day`` or ``-1 week``. + +
417-
+---------------+---------------------+--------------------------------------------------------------+-------------------------------------+
418-
+ default + default value + Displays the default value if the variable is empty or + { v|default(just in case) } +
419-
+ + + undefined. + +
420-
+---------------+---------------------+--------------------------------------------------------------+-------------------------------------+
421-
+ esc + html, attr, css, js + Specifies the context to escape the data. + { v|esc(attr) } +
422-
+---------------+---------------------+--------------------------------------------------------------+-------------------------------------+
423-
+ excerpt + phrase, radius + Returns the text within a radius of words from a given + { v|excerpt(green giant, 20) } +
424-
+ + + phrase. Same as **excerpt** helper function. + +
425-
+---------------+---------------------+--------------------------------------------------------------+-------------------------------------+
426-
+ highlight + phrase + Highlights a given phrase within the text using + { v|highlight(view parser) } +
427-
+ + + '<mark></mark>' tags. + +
428-
+---------------+---------------------+--------------------------------------------------------------+-------------------------------------+
429-
+ highlight_code+ + Highlights code samples with HTML/CSS. + { v|highlight_code } +
430-
+---------------+---------------------+--------------------------------------------------------------+-------------------------------------+
431-
+ limit_chars + limit + Limits the number of characters to $limit. + { v|limit_chars(100) } +
432-
+---------------+---------------------+--------------------------------------------------------------+-------------------------------------+
433-
+ limit_words + limit + Limits the number of words to $limit. + { v|limit_words(20) } +
434-
+---------------+---------------------+--------------------------------------------------------------+-------------------------------------+
435-
+ local_currency+ currency, locale + Displays a localized version of a currency. "currency" + { v|local_currency(EUR,en_US) } +
436-
+ + + valueis any 3-letter ISO 4217 currency code. + +
437-
+---------------+---------------------+--------------------------------------------------------------+-------------------------------------+
438-
+ local_number + type, precision, + Displays a localized version of a number. "type" can be + { v|local_number(decimal,2,en_US) } +
439-
+ + locale + one of: decimal, currency, percent, scientific, spellout, + +
440-
+ + + ordinal, duration. + +
441-
+---------------+---------------------+--------------------------------------------------------------+-------------------------------------+
442-
+ lower + + Converts a string to lowercase. + { v|lower } +
443-
+---------------+---------------------+--------------------------------------------------------------+-------------------------------------+
444-
+ nl2br + + Replaces all newline characters (\n) to an HTML <br/> tag. + { v|nl2br } +
445-
+---------------+---------------------+--------------------------------------------------------------+-------------------------------------+
446-
+ number_format + places + Wraps PHP **number_format** function for use within the + { v|number_format(3) } +
447-
+ + + parser. + +
448-
+---------------+---------------------+--------------------------------------------------------------+-------------------------------------+
449-
+ prose + + Takes a body of text and uses the **auto_typography()** + { v|prose } +
450-
+ + + method to turn it into prettier, easier-to-read, prose. + +
451-
+---------------+---------------------+--------------------------------------------------------------+-------------------------------------+
452-
+ round + places, type + Rounds a number to the specified places. Types of **ceil** + { v|round(3) } { v|round(ceil) } +
453-
+ + + and **floor** can be passed to use those functions instead. + +
454-
+---------------+---------------------+--------------------------------------------------------------+-------------------------------------+
455-
+ strip_tags + allowed chars + Wraps PHP **strip_tags**. Can accept a string of allowed + { v|strip_tags(<br>) } +
456-
+ + + tags. + +
457-
+---------------+---------------------+--------------------------------------------------------------+-------------------------------------+
458-
+ title + + Displays a "title case" version of the string, with all + { v|title } +
459-
+ + + lowercase, and each word capitalized. + +
460-
+---------------+---------------------+--------------------------------------------------------------+-------------------------------------+
461-
+ upper + + Displays the string in all uppercase. + { v|upper } +
462-
+---------------+---------------------+--------------------------------------------------------------+-------------------------------------+
463-
+ + + + +
464-
+---------------+---------------------+--------------------------------------------------------------+-------------------------------------+
405+
================ ================= =========================================================== ======================================
406+
Filter Arguments Description Example
407+
================ ================= =========================================================== ======================================
408+
abs Displays the absolute value of a number. { v|abs }
409+
410+
capitalize Displays the string in sentence case: all lowercase { v|capitalize}
411+
with firstletter capitalized.
412+
413+
date format (Y-m-d) A PHP **date**-compatible formatting string. { v|date(Y-m-d) }
414+
415+
date_modify value to add A **strtotime** compatible string to modify the date, { v|date_modify(+1 day) }
416+
/ subtract like ``+5 day`` or ``-1 week``.
417+
418+
default default value Displays the default value if the variable is empty or { v|default(just in case) }
419+
undefined.
420+
421+
esc html, attr, Specifies the context to escape the data. { v|esc(attr) }
422+
css, js
423+
424+
excerpt phrase, radius Returns the text within a radius of words from a given { v|excerpt(green giant, 20) }
425+
phrase. Same as **excerpt** helper function.
426+
427+
highlight phrase Highlights a given phrase within the text using { v|highlight(view parser) }
428+
'<mark></mark>' tags.
429+
430+
highlight_code Highlights code samples with HTML/CSS. { v|highlight_code }
431+
432+
limit_chars limit Limits the number of characters to $limit. { v|limit_chars(100) }
433+
434+
limit_words limit Limits the number of words to $limit. { v|limit_words(20) }
435+
436+
local_currency currency, locale Displays a localized version of a currency. "currency" { v|local_currency(EUR,en_US) }
437+
valueis any 3-letter ISO 4217 currency code.
438+
439+
local_number type, precision, Displays a localized version of a number. "type" can be { v|local_number(decimal,2,en_US) }
440+
locale one of: decimal, currency, percent, scientific, spellout,
441+
ordinal, duration.
442+
443+
lower Converts a string to lowercase. { v|lower }
444+
445+
nl2br Replaces all newline characters (\n) to an HTML <br/> tag. { v|nl2br }
446+
447+
number_format places Wraps PHP **number_format** function for use within the { v|number_format(3) }
448+
parser.
449+
450+
prose Takes a body of text and uses the **auto_typography()** { v|prose }
451+
method to turn it into prettier, easier-to-read, prose.
452+
453+
round places, type Rounds a number to the specified places. Types of **ceil** { v|round(3) } { v|round(ceil) }
454+
and **floor** can be passed to use those functions instead.
455+
456+
strip_tags allowed chars Wraps PHP **strip_tags**. Can accept a string of allowed { v|strip_tags(<br>) }
457+
tags.
458+
459+
title Displays a "title case" version of the string, with all { v|title }
460+
lowercase, and each word capitalized.
461+
462+
upper Displays the string in all uppercase. { v|upper }
463+
================ ================= =========================================================== ======================================
465464

466465
See `PHP's NumberFormatter <https://www.php.net/manual/en/numberformatter.create.php>`_ for details relevant to the
467466
"local_number" filter.
@@ -519,18 +518,19 @@ Provided Plugins
519518

520519
The following plugins are available when using the parser:
521520

522-
==================== ========================== ================================================================================== ================================================================
523-
Plugin Arguments Description Example
524-
==================== ========================== ================================================================================== ================================================================
525-
current_url Alias for the current_url helper function. {+ current_url +}
526-
previous_url Alias for the previous_url helper function. {+ previous_url +}
527-
siteURL Alias for the site_url helper function. {+ siteURL "login" +}
528-
mailto email, title, attributes Alias for the mailto helper function. {+ mailto email=foo@example.com title="Stranger Things" +}
529-
safe_mailto email, title, attributes Alias for the safe_mailto helper function. {+ safe_mailto email=foo@example.com title="Stranger Things" +}
530-
lang language string Alias for the lang helper function. {+ lang number.terabyteAbbr +}
531-
validation_errors fieldname(optional) Returns either error string for the field (if specified) or all validation errors. {+ validation_errors +} , {+ validation_errors field="email" +}
532-
route route name Alias for the route_to helper function. {+ route "login" +}
533-
==================== ========================== ================================================================================== ================================================================
521+
================== ========================= ============================================ ================================================================
522+
Plugin Arguments Description Example
523+
================== ========================= ============================================ ================================================================
524+
current_url Alias for the current_url helper function. {+ current_url +}
525+
previous_url Alias for the previous_url helper function. {+ previous_url +}
526+
siteURL Alias for the site_url helper function. {+ siteURL "login" +}
527+
mailto email, title, attributes Alias for the mailto helper function. {+ mailto email=foo@example.com title="Stranger Things" +}
528+
safe_mailto email, title, attributes Alias for the safe_mailto helper function. {+ safe_mailto email=foo@example.com title="Stranger Things" +}
529+
lang language string Alias for the lang helper function. {+ lang number.terabyteAbbr +}
530+
validation_errors fieldname(optional) Returns either error string for the field {+ validation_errors +} , {+ validation_errors field="email" +}
531+
(if specified) or all validation errors.
532+
route route name Alias for the route_to helper function. {+ route "login" +}
533+
================== ========================= ============================================ ================================================================
534534

535535
Registering a Plugin
536536
--------------------

0 commit comments

Comments
 (0)