View more context

(obviously replace ProjectHolder with whatever the parent page should be

Yeah, I don’t think the above snippet will stop people moving them into the wrong place after creating

or you can make a validator for that one that will be checking if it's in the right parent class

We have a client that want to embed <script> code in the CMS for his social media curator accounts which is fine but I cant get it to render as HTML , it just shows the code rather than rendering. Anyone got any ideas please?

Sorry I am not to sure what that is, I have tried the HTMLText field using embed source?

Sorry tinymce is WYSIWYG in that case yes I am

hang on - you're trying to embed a script tag in tinymce or is a separate field?

  1. <script type="text/javascript">
  2. /* curator-feed */
  3. (function(){
  4. var i, e, d = document, s = "script";i = d.createElement("script");i.async = 1;
  5. i.src = "";
  6. e = d.getElementsByTagName(s)[0];e.parentNode.insertBefore(i, e);
  7. })();
  8. </script>

and you're pasting that directly into the wysiwyg editor, or are you inserting it via the "source code" view of the editor?

He wants to add the above through the CMS but I cant get it render it just shows as you read it above

ok - pasting directly into the editor would convert everything to escaped HTML because it's meant to be a text entry form

you'd need to open the source code view and paste it there

BUT tinymce would remove script tags by default, so you'll need to allow them

see (edited)

  Script tags in TinyMCE fields are not saving correctly

Yeah soon as I save it inside source code view it clears it

that link should help me then , thank you

here's an example for how to enable it in SS: (edited)



  1. TinyMCEConfig::get('cms')
  2. ->setOptions([
  3. 'extended_valid_elements' => 'script[language|type|src]'
  4. ]);

Thank you - Do I use that code in _config.php or the class im trying to embed the script?

you'd be better to add a CuratorURL textfield to your page, allow them to put into it, then render the rest of the script tag in a template and insert the URL

Yeah I also tried that but it breaks curator for some reason

ok, well whichever way works for you is fine, but that'd be my suggestion - otherwise you're allowing anyone with CMS edit access to insert arbitrary javascript into any page on the site

I'll give both a go, thank you for your help 🙂

FYI we do something similar to this with an A/B tester tool on, TextField in the CMS for the URL and insert the rest of the script tag in a template if it's set. also common with google analytics tracking code - enter your code and then render the rest of the snippet in a template if it's set

Okay thank you I will check that out 🙂

+1 you really want this to go in the template and add plain text variables through the CMS