Monday, 26 August 2013

Populating js array in blade template

Populating js array in blade template

I'm trying to build a javascript array of data for use in flot from the
result of a php DB query.
When I'm outputting numbers ($lic->Users) it's fine, but whenever I try to
output a string I get a completely blank page in the browser.
I've tried:
{{ $lic->CompanyName }}
"<?php echo $lic->CompanyName; ?>"
{{{ $lic->CompanyName }}}
'"'+ <?php echo $lic->CompanyName; ?> +'"'
But when I hard-code it (to say, 'CompanyName'), it builds the bar graph
(& displays the page) just fine.
var data =
[
@foreach($licdata as $lic)
{
'label': "{{ $lic->CompanyName }}",
'data': [
["{{ $lic->CompanyName }}", {{ $lic->Users }}],
["{{ $lic->CompanyName }}", {{ $lic->Emps }}]
]
},
@endforeach
];
I think it must be something to do with quoting/escaping the string in js,
but I can't work out what, does anyone know what the correct syntax is?

No comments:

Post a Comment