I need a specific format that I build in my PHP and which is then sent to my view and the JavaScript (using Symfony, but this is not a Symfony issue).
The problem is specified in the title: the '
from the string is transformed into my js and I don't want it to be transformed
Here are how it looks like
PHP side
case "01":
$dynamic_month="['Février ".$previous_year."','Mars ".$previous_year."','Avril ".$previous_year."','Mai ".$previous_year."
','Juin ".$previous_year."','Juillet ".$previous_year."','Août ".$previous_year."','Septembre ".$previous_year."','Octobre
".$previous_year."','Novembre ".$previous_year."','Décembre ".$previous_year."','Janvier ".$year."']";
break;
This is building a string with something like ['Month Year','NextMonth Year']
(this is what a var_dump is printing.
But in my JavaScript (chart.js inside a twig view). The '
are replaced.
var chart = new Chart(ctx, {
// The type of chart we want to create
type: 'line',
// The data for our dataset
data: {
labels: {{ dynamic_month }},
datasets: [{
label: "Connexion / mois",
backgroundColor: 'rgb(255, 99, 132)',
borderColor: 'rgb(255, 99, 132)',
data: connectedByMonth,
}]
},
// Configuration options go here
options: {}
});
The issue is on the line
labels: {{ dynamic_month }}
this is replaced once compiled by this
labels: ['Février 2018','Mars 2018', et caetera et caetera