1

I am trying to include a very simple snippet of CSS and JavaScript to a Modx page that lists recent newsletters from MailChimp:

<style type="text/css">
.display_archive {font-family: arial,verdana; font-size: 12px;}
.campaign {line-height: 125%; margin: 5px;}
</style>
<script language="javascript" src="//ZZZZ.us11.list-manage.com/generate-js/?u=XXXXX&fid=YYYYY&show=10" type="text/javascript"></script>

The <script> tag is returning a document.write() that outputs a list of links.

Unfortunately it looks like TinyMCE blocks <style> and <script> tags and this code is not being added. What is the best way to add this code chunk to a specific page?

I found this page that shows ways to add code to the <head> or <body> tags, but I am looking to insert the code on a specific part of the page (since it does document.write, the placement is important.

I was thinking an alternative is to create a snippet that does:

$response = file_get_contents('https://ZZZZZ.us11.list-manage.com/generate-js/?u=XXXXX&fid=YYYYY&show=10')
// remove "document.write"
// unescape slashes
return $clean_html;

But this does not seem like it would be the best method.

Bijan
  • 7,737
  • 18
  • 89
  • 149

1 Answers1

0

You can try wrapping your whole block in <code></code> tags.

<code>
    <style type="text/css">
        .display_archive {font-family: arial,verdana; font-size: 12px;}
        .campaign {line-height: 125%; margin: 5px;}
    </style>
    <script language="javascript" src="//ZZZZZ.us11.list-manage.com/generate-js/? 
    u=XXXXX&fid=YYYYY&show=10" type="text/javascript"></script>
</code>

Another option is to go into the TinyMCS config files and add script and style to the extended_valid_elements. Something like:

.AddSetting("extended_valid_elements", "script[*],style[*]")

Exactly how it's done (and whether possible) will depend on which TinyMCE plugin you're using. Some plugins allow for more configuration than others.

Another solution: (assuming the problem is you want to have editable rich text content before AND after the style and script tags) -- add two rich text boxes to the page template with the chunk containing your style and script tags in between them. For instance in the template you could have:

[[*content]]
[[$chunkWithTags]]
[[*anotherRichTextTV]]
Bijan
  • 7,737
  • 18
  • 89
  • 149
LIannotti
  • 382
  • 1
  • 11
  • The code is removed even when wrapped in `` tags. Wouldnt adding script/style to `extended_valid_elements` pose a security issue? – Bijan Mar 08 '23 at 23:06
  • I’ll leave the question regarding security to the experts, but I will say that getting TinyMCE to allow script tags is exactly what you are trying to do. So I see no difference between your stated goal and this solution to it. – LIannotti Mar 09 '23 at 15:07