JsonViewHelper extends AbstractViewHelper uses CompileWithContentArgumentAndRenderStatic
This class is the implementation of a Fluid ViewHelper.
View this class in the TYPO3 ViewHelper reference: <f:format.json>
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"}
Table of Contents
Properties
- $escapeChildren : bool
Methods
- initializeArguments() : mixed
- Initialize arguments
- renderStatic() : string
- Applies json_encode() on the specified value.
Properties
$escapeChildren
protected
bool
$escapeChildren
= false
Methods
initializeArguments()
Initialize arguments
public
initializeArguments() : mixed
renderStatic()
Applies json_encode() on the specified value.
public
static renderStatic(array<string|int, mixed> $arguments, Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) : string
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
- $arguments : array<string|int, mixed>
- $renderChildrenClosure : Closure
- $renderingContext : RenderingContextInterface