‪TYPO3CMS  10.4
TYPO3\CMS\Fluid\ViewHelpers\Format\JsonViewHelper Class Reference
Inheritance diagram for TYPO3\CMS\Fluid\ViewHelpers\Format\JsonViewHelper:

Public Member Functions

 initializeArguments ()
 

Static Public Member Functions

static string renderStatic (array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
 

Protected Attributes

bool $escapeChildren = false
 

Detailed Description

Wrapper for PHPs :php:json_encode function. See https://www.php.net/manual/function.json-encode.php.

Examples

Encoding a view variable

::

{someArray -> f:format.json()}

["array","values"] Depending on the value of {someArray}.

Associative array

::

{f:format.json(value: {foo: 'bar', bar: 'baz'})}

{"foo":"bar","bar":"baz"}

Non associative array with forced object

::

{f:format.json(value: {0: 'bar', 1: 'baz'}, forceObject: true)}

{"0":"bar","1":"baz"}

Definition at line 61 of file JsonViewHelper.php.

Member Function Documentation

◆ initializeArguments()

TYPO3\CMS\Fluid\ViewHelpers\Format\JsonViewHelper::initializeArguments ( )

Initialize arguments

Definition at line 71 of file JsonViewHelper.php.

◆ renderStatic()

static string TYPO3\CMS\Fluid\ViewHelpers\Format\JsonViewHelper::renderStatic ( array  $arguments,
\Closure  $renderChildrenClosure,
RenderingContextInterface  $renderingContext 
)
static

Applies json_encode() on the specified value.

Outputs content with its JSON representation. To prevent issues in HTML context, occurrences of greater-than or less-than characters are converted to their hexadecimal representations.

If $forceObject is TRUE a JSON object is outputted even if the value is a non-associative array Example: array('foo', 'bar') as input will not be ["foo","bar"] but {"0":"foo","1":"bar"}

Parameters
array$arguments
\Closure$renderChildrenClosure
RenderingContextInterface$renderingContext
See also
https://www.php.net/manual/function.json-encode.php
Returns
‪string

Definition at line 92 of file JsonViewHelper.php.

Member Data Documentation

◆ $escapeChildren

bool TYPO3\CMS\Fluid\ViewHelpers\Format\JsonViewHelper::$escapeChildren = false
protected

Definition at line 66 of file JsonViewHelper.php.