How to pass a component setting as a value to an attribute?

Hi, I’m simply trying to add an external script library via a <script src="..."></script> tag in the head_tag.html template like this, clearly not the correct syntax.

<script type="text/discourse-plugin" version="1.6.0">

  <script src="https://example.com/library.js"
        charset="UTF-8"
        data-lib-xyz=`${ settings.data_lib_xyz }`
        />

</script>

And I get an error, as soon as I enable it:

SyntaxError: /discourse/theme-8/initializers/theme-field-54-common-html-script-1: Support for the experimental syntax ‘jsx’ isn’t currently enabled (14:3):

What would be the Discourse way of using a theme setting value for a SCRIPT tag’s attribute value?

Hi Osman,

This might be the best place to start: Theme Developer Quick Reference Guide.

There’s also a great deal of info on the pluginAPI here: Beginner's guide to developing Discourse Themes, including code demos.

You’ll also want to look at our CSP documentation if you’re adding scripts, so that they’ll be allowed to run: Mitigate XSS Attacks with Content Security Policy.

I hope that helps, but as always, feel free to send through additional questions.

Mark

1 Like