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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

get file upload url for passing to js

Go to End

3 Posts   2959 Views


Community Member, 26 Posts

25 October 2010 at 12:15pm

So following the execellent advice from my last thread i created some variables and passed them to some js.
I now need to pass the url of a file upload to the js.

$fields->addFieldToTab("Root.Content.Embed", new FileIFrameField('GPSXML', 'Upload and Attach Document'));

public function init() {
		Requirements::javascriptTemplate('mysite/javascript/maps.js', array( 
			'GPSXML' => $this->GPSXML.URL 

This doesnt seem to pass anything over to the js the alert box for $GPSXML just shows blank. I'm guessing i need to parse out the url as a string? any ideas?

thx guys


Community Member, 98 Posts

5 November 2010 at 3:46am

Edited: 05/11/2010 3:46am


I had the same problem as you. By inspecting the Requirements::javascriptTemplate() method I found that you do need to encapsulate the replaceable variable name with quotes. Due to the way the variable is replaced, I would also recommend referencing it only once, and assigning it to a 'real' javascript variable, like so:


		Requirements::javascriptTemplate('script.js', array(
			"vimeoID" => $this->vimeoID()


var vimeoID = '$vimeoID';

The Requirements::javascriptTemplate() method is a little used and little documented feature, but a handy one nonetheless. I hope this helps those trying to use it in the future...


Community Member, 26 Posts

7 November 2010 at 4:43pm

Edited: 07/11/2010 4:52pm

this worked for getting the value of vimeoID because it was just a text field. Here i want to pass the url of the filefieldupload.

it actually works fine if i create a text field and have the user manually enter the url but it would be much better if i could get the url straight from the file upload.

thanks heaps for all your help so far.