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.

Customising the CMS /

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

Custom Javascript in the Admin


Go to End


2 Posts   4071 Views

Avatar
JonShutt

Community Member, 244 Posts

26 February 2013 at 4:35pm

I'm trying to add custom javascript to a tab in the CMS admin area

I can include the javascript easy enough by adding the following to the _config.php file

LeftAndMain::require_javascript('mysite/javascript/ContactPageAdmin.js');

However, the file loads in only once, when the CMS is first opened.
I need to run the script when the contact page is loaded in CMS.
And not just when it's loaded, but when it's saved, it needs to run again to refresh the content

Avatar
kinglozzer

Community Member, 187 Posts

26 February 2013 at 11:03pm

You'll need to use Entwine for this, see here:
http://doc.silverstripe.org/framework/en/topics/javascript

The best way to learn how Entwine works is to look at, for example, /framework/admin/javascript/LeftAndMain.EditForm.js.

I've recently done a similar thing, that calls a function whenever it detects a field (used for Google Maps):
https://github.com/kinglozzer/SilverStripe-GMapsPage/blob/master/javascript/GMapsPage.js