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.

Était-ce utile?

La solution

You can use :

$build['test'] = [
  '#children' => $test_code,
];
Licencié sous: CC-BY-SA avec attribution
Non affilié à drupal.stackexchange
scroll top