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.

Was it helpful?

Solution

You can use :

$build['test'] = [
  '#children' => $test_code,
];
Licensed under: CC-BY-SA with attribution
Not affiliated with drupal.stackexchange
scroll top