Rendering Marketo Embedded code in controller.php

Highlighted

Rendering Marketo Embedded code in controller.php

hi all,

I am trying to implement a form in our drupal 8 website. The trick is all the pages on our website, is a module itsself.

Previously we had hubspot which was rendered as :

`return [

      '#type' => 'container',

      '#attributes' => [

        'class' => [

          'contact-forms',

        ],

      ],

      'title' => [

        '#type' => 'markup',

        '#markup' => '<h2>XYZ</h2>',

      ],

      'hubspot-contact-form' => [

        '#type' => 'markup',

        '#markup' => \Drupal::service('renderer')->render($form),

      ],

      '#attached' => [

        'library' => [

          'phenom_hubspot/hubspot-form',

        ],

      ],

    ];`

But now, on writing the embedded code in the #markup, yeilds only the code on the page. Please help. Have been stuck on the process for days now. Thanks

5 REPLIES 5
Highlighted

Re: Rendering Marketo Embedded code in controller.php

Can you paste a link to a page where this is happening?

I have seen some systems throw random p tags around code snippets which cause that to happen.

Highlighted
Level 10 - Community Moderator

Re: Rendering Marketo Embedded code in controller.php

Like Gerard says, you must provide a URL so we can see the final output.

It could be that your render method (which is completely opaque to us, please remember we aren't seeing anything you're using on the back end and Marketo is not a Drupal site) is escaping the HTML tags, which obvs. needs to be turned off.

And always highlight your code when posting, using the Advanced Editor's syntax highlighter:

https://s3.amazonaws.com/blog-images-teknkl-com/syntax_highlighter.gif

Highlighted

Re: Rendering Marketo Embedded code in controller.php

I second Sanford. If you just google "Drupal removes script tags" there is a ton of forums and posts talking about how various WYSIWYG editor and other plugins strip them out. There is also just as many solutions.

Highlighted

Re: Rendering Marketo Embedded code in controller.php

Thank you Gerard and Sanford. It is indeed my lucky day. At the moment i am able to render the form. All i needed to do was to add 'script' in #allowed_tags.

Eg:

'#allowed_tags' => ['div',], ];
Highlighted
Level 10 - Community Moderator

Re: Rendering Marketo Embedded code in controller.php

OK, but please don't delete other people's posts by removing yours. People put in lots of effort here and it isn't fair to delete their work.