I have a custom view and a custom row template. For each row, the template defines a variable $rowdata. For example:
> row #0: $rowdata = array(0=>array('a','b'), 1=>array('a','c'))
> row #1: $rowdata = array(0=>array('a','b'), 1=>array('a','d'))
> row #2: $rowdata = array(0=>array('x'), 1=>array('x'))
What I Am Trying To Accomplish
I want merge the rowdata from all the rows:
$merged_rowdata = array(
0=>array('a','b'),
1=>array('a','c'),
2=>array('a','b'),
3=>array('a','d'),
4=>array('x'),
5=>array('x')
)
and store the result in Drupal.settings.mymodule.$viewID.merged_rowdata
:
Drupal.settings.mymodule.$viewID.merged_rowdata = array(
0=>array('a','b'),
1=>array('a','c'),
2=>array('a','b'),
3=>array('a','d'),
4=>array('x'),
5=>array('x')
)
(Note: All rows have the same value for $viewID)
What I Tried
I tried placing the following code in my row template:
drupal_add_js(array('mymodule' => array($viewID => array('merged_rowdata' => $rowdata))), 'setting');
But this does not merge the rowdata in the way that I want, as described above. Instead, it replaces $viewID with the row_index:
Drupal.settings.mymodule = array(
0 => array('merged_rowdata'=>array(0=>array('a','b'), 1=>array('a','c'))),
1 => array('merged_rowdata'=>array(0=>array('a','b'), 1=>array('a','d'))),
2 => array('merged_rowdata'=>array(0=>array('x'), 1=>array('x')))
)
I found that if I replace the variable $viewID with a string literal, eg 'myview':
drupal_add_js(array('mymodule' => array('myview' => array('merged_rowdata' => $rowdata))), 'setting');
then the rowdata gets merged in the way that I want:
Drupal.settings.mymodule.myview.merged_rowdata = array(
0=>array('a','b'),
1=>array('a','c'),
2=>array('a','b'),
3=>array('a','d'),
4=>array('x'),
5=>array('x')
)
Anyone know how I can get my desired result? Is there some way to "tell" drupal_add_js that the variable $viewID has the same value for all the rows?
Background
My style template loops through each row of the view output, and executes the row template on each row. Here is the code for my style template:
<?php foreach ($rows as $id => $row): ?>
<div>
<?php print $row; ?>
</div>
<?php endforeach; ?>
foreach
loop that gets processed by another template file)... Can you post the name and contents of the template file?