Drupal 8 - Add custom HTML with script to embed on a page as block
-
18-02-2021 - |
Question
I need to add a custom form that has scripts and styles into a page as a block. Its dynamic, so I couldn't attach the scripts (#attached) as libraries. I just need to place the contents as is.
$build['test'] = [
'#markup' => $test_code,
'#allowed_tags' => [
'script',
'style',
'form',
'input',
],
];
I tried it as shown above, but this wasn't working. So, I removed, scripts and style as shown below and that works:
$build['test'] = [
'#markup' => $test_code,
'#allowed_tags' => [
'form',
'input',
],
];
Any possible solution to render the contents without filtering scripts and style.
La solution
You can use :
$build['test'] = [
'#children' => $test_code,
];
Licencié sous: CC-BY-SA avec attribution
Non affilié à drupal.stackexchange