Drupal 7 自定义页面如何向自定义的主题传参

xiaoxiao2021-02-27  297

根据 https://www.drupal.org/node/1560952 的介绍,我自定义了一个页面内容如下,数据都取到了,现在问题是数据没有按着实例传到主题变量中。

<?php function metest_theme(){ return array( 'metest'=>array( 'variables'=>array('output'=>null), 'template'=>'metest', ), ); } function metest_menu(){ $items=array(); $items['rfid/showme']=array( 'title'=>t('ME'), 'description'=>t('ME'), 'page callback' => 'metest_page', 'access callback'=>TRUE, ); $items['rfid-showme/%/%']=array( 'title'=>t('ME'), 'description'=>t('ME'), 'page callback' => 'metest_page_results', 'page arguments'=>array(1,2), 'access callback'=>TRUE, ); return $items; } function metest_page(){ /* $dis=drupal_get_form('metest_kanban_form'); return $dis; */ return array('#markup'=>t('请选择左边栏')); } function metest_page_results($pro_date,$pro_line){ $output=metest_get_me_result($pro_line,$pro_date); dpm($output); return theme('metest',array('output'=>$output)); } function metest_block_info() { $blocks = array(); $blocks['mekanban'] = array( 'info' => t('ME'), 'cache' => DRUPAL_NO_CACHE, ); return $blocks; } function metest_block_view($delta = '') { $block = array(); switch ($delta) { case 'mekanban': $block['subject'] = t('ME'); $block['content'] = drupal_get_form('metest_kanban_form'); break; } return $block; } function metest_kanban_form($form, &$form_state){ global $user; $options=metest_kanban_get_lines(); $date_format='Y-m-d'; $form=array(); $pro_line=variable_get('me_pro_line'.$user->uid,$pro_line); $form['linelist']=array( '#prefix'=>'<span class="right_arrow"></span>', '#type'=>'select', '#size'=>10, '#empty_option' => t('选择组'), '#options' => $options, '#default_value'=>$pro_line, ); $form['productiondate']=array( '#type'=>'date_popup', '#title'=>t('选择日期'), '#default_value'=>variable_get('me_pro_date'.$user->uid,date('Y-m-d')), '#date_format'=>$date_format, '#date_label_position'=>'within', '#date_timezone'=>'Asia/Shanghai', '#date_increment'=>60, '#date_year_rang'=>'-3:+3', ); $form['submit']= array( '#type' => 'submit', '#value' => t('提交'), ); return $form; } function metest_kanban_get_lines(){ $options=array(); $results=taxonomy_get_tree(12); foreach($results as $term ){ $key=$term->tid; $value=$term->name; $term_load=taxonomy_term_load($term->tid); $options[$key]=$value; } return $options; } function metest_kanban_form_submit($form, &$form_state){ $linelist=$form_state['values']['linelist']; $productiondate=$form_state['values']['productiondate']; if(!empty($linelist)&& !is_null($productiondate)){ global $user; variable_set('me_pro_date_'.$user->uid,$productiondate); variable_set('me_pro_line_'.$user->uid,$linelist); drupal_goto(file_create_url('/rfid-showme/'.$productiondate.'/'.$linelist)); } } function metest_get_me_result($line,$prodate){ $query=db_select('node','n'); //... $query->OrderBy('n.created','DESC'); $result=$query->execute()->fetchAll(); return $result; }在metest.tpl.php中读$output,但没有成功,不知道是何原因,模板文件放在jean自定义的主题文件夹内../jean/template/metest.tpl.php

<?php dpm($output);?>此图是 metest_page_results()中的dpm输出的调试,说明数据取到了,现在最关键就在后面的theme()没有传递成功。

转载请注明原文地址: https://www.6miu.com/read-3212.html

最新回复(0)