Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Template Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

$ThemeDir won't work with Js images


Go to End


3 Posts   1523 Views

Avatar
D0bl1nk

Community Member, 3 Posts

7 October 2016 at 10:44pm

Can't find a solution in the Lessons

        Requirements::javascript($this->ThemeDir()."/js/script.js");
                  Requirements::javascript($this->ThemeDir()."/js/jquery.backstretch.min.js");

  $('.homepage-jumbo').backstretch([
        "$ThemeDir/images/loginbackground.jpg",
        "$ThemeDir/images/test1.jpg",
        "$ThemeDir/images/test2.jpg"
    ], {
        fade: 750,
        duration: 4000
    });

Avatar
Devlin

Community Member, 344 Posts

7 October 2016 at 11:09pm

Either:

// Page.php
Requirements::javascript($this->ThemeDir()."/js/script.js");
Requirements::javascript($this->ThemeDir()."/js/jquery.backstretch.min.js");
$ThemeDir = $this->ThemeDir();
Requirements::customScript(<<<JS
	console.log('$ThemeDir');
JS
);

Or:

// Page.php
Requirements::javascript($this->ThemeDir()."/js/script.js");
Requirements::javascript($this->ThemeDir()."/js/jquery.backstretch.min.js");
Requirements::javascriptTemplate($this->ThemeDir()."/js/myJSFile.js", ["ThemeDir" => $this->ThemeDir()]);

// myJSFile.js
console.log('$ThemeDir');

Or:

// Page.ss
<script type="text/javascript">
console.log('$ThemeDir');
</script>

Avatar
D0bl1nk

Community Member, 3 Posts

13 January 2017 at 6:43pm

Edited: 13/01/2017 8:33pm

Sorry for the late reply i didn't subscribed to the topic

Thanks it worked. However your solutions caused an uncaught error

Uncaught TypeError: Cannot read property 'config' of undefined
at o (scrollreveal.min.js?m=1482637582:1)

I'll will just insert the script when needed for now