JsonViewHelper extends AbstractViewHelper uses CompileWithContentArgumentAndRenderStatic

ViewHelper

This class is the implementation of a Fluid ViewHelper.

View this class in the TYPO3 ViewHelper reference: <f:format.json>

FinalYes

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()  : void
renderStatic()  : string|false
Applies json_encode() on the specified value.
resolveContentArgumentName()  : string
Explicitly set argument name to be used as content.

Properties

$escapeChildren

protected bool $escapeChildren = false

Methods

initializeArguments()

public initializeArguments() : void

renderStatic()

Applies json_encode() on the specified value.

public static renderStatic(array<string|int, mixed> $arguments, Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) : string|false

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
Tags
see
https://www.php.net/manual/function.json-encode.php
Return values
string|false

resolveContentArgumentName()

Explicitly set argument name to be used as content.

public resolveContentArgumentName() : string
Return values
string

        
On this page

Search results