score:8
Accepted answer
Quick & "dirty" answer : set the variable in your TWIG file using balises, and use those vars in your JS file.
<script>
var foo = {{ bar }};
</script>
score:14
You can generate javascript as twig template:
MonthsController.php
public function scriptAction()
{
// some logic
return $this->render('AcmeDemoBundle:Months:script.js.twig', array(
'user_months' => $user_months
));
}
routing.yml
javascript_route:
path: /generated-scripts/month.{_format}
defaults: { _controller: AcmeDemoBundle:Article:script, _format: js }
requirements:
_format: js|json
script.js.twig
$(function () {
var options = {
chart: {
type: 'bar'
},
title: {
text: 'Budget for months'
},
xAxis: {
categories: ['Spent', 'Saved']
},
yAxis: {
title: {
text: 'Fruit eaten'
}
},
series: []
};
{% for user in user_months %}
options.series.push({ name: '{{ user.name }}', data: [{{ user.months|join(',') }}] };);
{% endfor %}
$('#container').highcharts(options);
});
Source: stackoverflow.com
Related Query
- Send variables from Symfony2 PHP file to js file
- HIGHCHARTS - Jquery/Ajax access php variables from the php file called by ajax
- How to send json to highcharts from php
- load data from text file into HIGHCHART graphic using PHP
- How do I pass a PHP variable from one file to another multiple times?
- Highcharts Won't load from php json, but it could load from data.json file
- Send JSON data to highcharts pie from asp.net MVC controller in C#
- Pass function to jquery from php
- Using PhantomJS to create HighCharts grahps server side for use in PDF creation (PHP) - results in exit code 11 from PHPs exec();
- How to populate a Highcharts axis with string formatted data from a PHP array
- JavaScript code inside TypeScript file .ts not working
- Passing a JavaScript function from JSON encoded PHP
- c# WPF Webbrowser with Highchart, Javascript from external source not working "An error has occurred in the script on this page"
- How to add php data into highchart js file in php
- PHP - getting real time data from the database
- Highcharts multiple series json from php
- Generate image in a folder from Highchart in PHP
- Pass a textfield value from php to javascript
- passing json values to highcharts from .net code behind
- Highcharts series setData from ajax php procedure
- Generating Highcharts from MySQL data with PHP does not work
- Remove Square Bracket From Array Key PHP
- How can i export row data from highchart to excel file and not csv?
- Simple, Open source PHP wrapper for Highcharts library
- Use value from prompt as highcharts export file name
- Creating a Highchart with multiple series from a JSON file
- Remove gap in Highcharts column chart from null value from JSON file in React
- Highcharts dynamicly update chart from csv file
- Generating json data for StockChart from PHP
- Highcharts not displaying data but drawing chart when reading from CSV file
More Query from same tag
- Webpack Highcharts Plugin IIFE
- Issue: In case of multiLineSeries Graph if one of the series has no Data, the entire graph does not get plotted
- Highcharts Tooltip display different data
- Highcharts - "Archery Range" chart?
- Stacked column inside drilldown - HighCharts
- Highcharts not formatting tooltip datetime according to xDateFormat setting
- Is it possible to have synchronized charts with error lines?
- Highcharts solid gauge dynamic update
- how to use customise hight chart as shown in image?
- HighCharts performance degrades dramatically with 'chart' and 'renderer' together
- Highcharts legend js error
- No output while reading json file in Highcharts
- How do you remove the partialFill from Highcharts xrange chart
- jQuery - Div doesn't fit page content
- Highcharts, show total data as a live stream
- Not able to load local csv data into Highcharts
- How can I make React Native in Android aware of a click event in a tooltip in a Highcharts chart?
- How to generate chart/graph on node.js as an html file
- how to display two charts on one page using angular2
- How to set scrollbar in highchart tooltip?
- How to highlight points of multi series in same X value when mouse moves using highcharts?
- Formatter Function not working in Highstocks
- HighChart timestamp highlight the time now
- Highcharts xAxis with datetime not showing any chart
- HighCharts : Exporting jpeg with background in styled mode
- How to distinguish Highcharts background color for if statement
- How to get max value by comparing dual y-axis in highchart?
- Hightcharts: reset the graph
- How to hide xAxis category of a hidden series in highcharts boxplot?
- Highcharts export customize axis label and fontsize: No effect after migration