Jump to:

23472 Posts in 18941 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » Send values to javascript within a template control block

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: 557 Views
  • jumprock
    Avatar
    Community Member
    8 Posts

    Send values to javascript within a template control block Link to this post

    Hi, I am trying dynamically push values from a Page Control into some inline JavaScript in a .ss Template as such:

    <% control MyControl %>
    <script>my_javascript_array.push($MyControlValue)</script>
    <% end_control %>

    The JavaScript that gets outputted to HTML is:

    <script>my_javascript_array.push()</script>

    That is, all values come out blank. I know this control has data because if I remove the script tags within the control block the values appear in the HTML fine.

    Is what I am trying to do possible?? If so, what am I doing wrong?

  • Nivanka
    Avatar
    Community Member
    395 Posts

    Re: Send values to javascript within a template control block Link to this post

    So do you mean if you take off the script tags then the value gets printed, if so a work around solution will be to add those scrip tags out of the <% control %> block.

    Out of question don't you need quotes around the argument you pass to the js push method?

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