Get plugin options from inside JS

Hello~

I was wondering if there's any way to grab data from a plugins setting from within a js file. I'd just want to pull the number value from a setting and use it in a function. Thank you :).

Comments

  • BleistivtBleistivt Moderator
    edited April 2015

    In your plugin:

    $Sender->AddDefinition('Specialnumber', C('Plugins.MyPlugin.SpecialNumber', 5));
    

    Javascript:

    alert('The special number is ' + gdn.definition('SpecialNumber'));
    

    Note that gdn.definition() returns the given string if the definition is not set (which Javascript evaluates to true in a condition), as it is mostly used for translations. In the future, gdn.getMeta() should be used for everything that is not a translation.

Sign In or Register to comment.