This is a part of my script in template file where php code is used to generate js field of objects:
<?php $count = count($events); $counter = 1; ?>
<script>
var events = [
<?php foreach($events as $event) { ?>
{
date: '<?php echo $event['date']; ?>',
linkTarget: "_blank",
content: "<?php echo $event['content']; ?>",
class: "<?php echo $event['class']; ?>"
}
<?php if($counter!=$count) { echo ','; $counter++; } ?>
<?php } ?>
];
<script>
I know that we can add js variable by drupal_add_js(array('myModule' => array('key' => 'value')), 'setting');
but how can we create the same js array as in example above in order not to use php code in js?