function TwigTransTest::testTransRenderArray
Testing trans with render array value.
File
-
core/
modules/ system/ tests/ src/ Functional/ Theme/ TwigTransTest.php, line 131
Class
- TwigTransTest
- Tests Twig "trans" tags.
Namespace
Drupal\Tests\system\Functional\ThemeCode
public function testTransRenderArray() : void {
$elements = [
'#type' => 'inline_template',
'#template' => '{% trans %}This is a {{ var }}.{% endtrans %}',
'#context' => [
'var' => [
'#prefix' => '<strong>',
'#markup' => 'trans render array',
'#suffix' => '</strong>',
],
],
];
/** @var \Drupal\Core\Render\RendererInterface $renderer */
$renderer = \Drupal::service('renderer');
$text = (string) $renderer->renderInIsolation($elements);
$this->assertSame('This is a <strong>trans render array</strong>.', $text);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.