2

I have a module name mysite.module in that module I have function named mysite_preprocess_panels_pane. That has an array and I would like to render this array inn panel.tpl.php. My code does not work. Any suggestion please, Thanks.

function mysite_preprocess_panels_pane(&$variables) {  
 $ar = array('arg1'=> 'car', 'arg2'=> 'truck');
}

<div class="pane-content">
<div class="panel-panel panel-col-first"> <?php print  $ar['arg1']></div>
</div>
0

You can do it with the following code.

function mysite_theme() {
  return array(
    'panel' => array(
      'render element'=>'element', 
      'template'=>'panel', 
      'variables'=>array( 'dataar'=>NULL ), 
    )); 
}

function mysite_preprocess_panels_pane(&$variables) {  
 $ar = array('arg1'=> 'car', 'arg2'=> 'truck');
 return theme('panel',array("dataar"=>$ar));
}

// The array will be accessed in the panel.tpl.php with $dataar variable

Please clear cache to reflect the changes from admin/config/development path

Hope it will work for you!

  • Thanks, But i got this error when I print datarr like this <div class="panel-panel panel-col-first">a <?php print $dataar['arg1'];?> </div>. Notice: Undefined variable: dataar in include() (line 42 of C:\xampp\htdocs\expressposmm\sites\all\modules\panels-7.x-3.0\panels\templates\panels-pane.tpl.php). – SAWAUNG Aug 14 '14 at 6:28
0

Place the array into the variables. like.

function mysite_preprocess_panels_pane(&$variables) {  
 $variables['ar'] = array('arg1'=> 'car', 'arg2'=> 'truck');
}
  • Thank Leopathu, but I this error, Warning: Invalid argument supplied for foreach() in element_children() (line 6433 of C:\xampp\htdocs\expressposmm\includes\common.inc). Warning: Illegal string offset '#children' in drupal_render() (line 5898 of C:\xampp\htdocs\expressposmm\includes\common.inc). – SAWAUNG Aug 14 '14 at 7:35
  • You can only render() a render array - rendering a non-render array will produce errors – Clive Aug 14 '14 at 8:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.