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.

Customising the CMS /

Custom Javascript in the Admin


Reply


2 Posts   1009 Views

Avatar
Futureweb

Community Member, 233 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, 175 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