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.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

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

Send values to javascript within a template control block


Go to End


2 Posts   946 Views

Avatar
jumprock

Community Member, 8 Posts

2 December 2011 at 12:05pm

Edited: 02/12/2011 12:06pm

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?

Avatar
Nivanka

Community Member, 400 Posts

3 December 2011 at 2:31pm

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?