Jump to:

23459 Posts in 18906 Topics by 2877 members

General Questions

SilverStripe Forums » General Questions » get file upload url for passing to js

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

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

Page: 1
Go to End
Author Topic: 1600 Views
  • slavelabourer
    Avatar
    Community Member
    25 Posts

    get file upload url for passing to js Link to this post

    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() {
          parent::init();
          
          Requirements::themedCSS("layout");
          Requirements::themedCSS("typography");
          Requirements::themedCSS("form");
          
          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

  • timwjohn
    Avatar
    Community Member
    98 Posts

    Re: get file upload url for passing to js Link to this post

    Hi,

    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:

    PHP:

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

    script.js:

    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...

  • slavelabourer
    Avatar
    Community Member
    25 Posts

    Re: get file upload url for passing to js Link to this post

    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.

    1600 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.