Jump to:

22972 Posts in 11596 Topics by 2824 members

General Questions

SilverStripe Forums » General Questions » value from the database into javascript

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: 967 Views
  • steve_nyhof
    Avatar
    Community Member
    224 Posts

    value from the database into javascript Link to this post

    public static $db = array(
    'TrackingName' => 'HTMLText'
    );

    function getCMSFields() {
    $fields = parent::getCMSFields();
    $fields->addFieldToTab("Root.Content.Main", new TextField('TrackingName','Tracking Code Name'));

    ---

    How do I get this value from the database for the page I am on, and pass it to a javascript var? Maybe metadata

    var trackingname = $TrackingName (I know this isn't right - this idea)

  • steve_nyhof
    Avatar
    Community Member
    224 Posts

    Re: value from the database into javascript Link to this post

    Well, not sure if this is ok or not, but it works.

    var trackingname = $TrackingName works

    My TrackingName field - I entered "test" and it passed it into the script!

    Better yet, I added the quote around the name and that worked also... var trackingname = "$TrackingName"

    Then I just entered the name of my code in the field.

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