Prevent Template parser to parse javascript

Silverstripe Version:
4.5
Question:
I am trying to implement JSSOR slider into a system,
it uses a code like this for initialization:
The problem is, that all $Bla variables are parsed and deleted by SS template parser - is there any trick to prevent this?

<script type="text/javascript">

                jQuery(document).ready(function ($) {

                    var _SlideshowTransitions = [{

                        $Duration: 600,

                        $Delay: 50,

Kind of odd for that plugin to want variables in that format but nothing you can do about that!

If there’s a way to do this out of the box I don’t know what it is. All I can think of (untested) is to use TemplateGlobalProvider to add a method that would be available to all templates that just takes in and returns a string. Something like

public static function NoParse($string)
{
    return DBField::create_field('HTMLText', $string);
}

Then in your template you could do $NoParse('$Duration').

Here’s an example of using TemplateGlobalProvider.

I guess it could also be worth trying to just put a backslash before the dollar sign in you template?

What an odd choice to use $Var like that.

Can you not put it in a JS file? If not, I added this

	public function SomeSlider()
	{
		return '
		<script type="text/javascript">
			jQuery(document).ready(function ($) {

				var _SlideshowTransitions = [{
					$Duration: 600,
					$Delay: 50,
				}];
			});
		</script>';
	}

to PageController and in any template call it with $SomeSlider.RAW and appears in the DOM fine.

Pretty dirty though…

Hi there,
thanks for your answers!

My solution finally is:

(Its only used in article-details)
$this->jssorScript = file_get_contents(PageController::ThemePath() . “/php-templates/jssor_script.php”);
(so I can edit the script via a backend editor)

And in the template just:
$jssorScript.RAW
before the slider html