2017-09-04 107 views
0

我想在模块中传递值到页面tpl文件在drupal.I创建了一个自定义模块'one_time_popup'。我创建了一个示例soutput并试图通过它并在页面中打印.tpl.php页脚section.but后不显示任何thing.What我做wrong.I'm新手获取从模块到模板的值

function one_time_popup_menu(){ 
$items['oneTimePopupData'] = array(
'title' => 'One time Popup', 
'page callback' => 'one_time_popup_user_login', 
'type' => MENU_CALLBACK, 
'access callback' => TRUE, 
); 
return $items; 
} 
function one_time_popup_user_login(&$edit, $account){ 
... 
$output='value from one time popup module!'; 
return theme('photo_order',array('results' => $output)); 
} 
function one_time_popup_theme() { 
return array(
'photo_order' => array(
    'template' => 'page', 
    'variables' => array(
    'results' => NULL, 
), 
), 
); 
} 

Tpl file(page.tpl) 
<?php echo $results; ?> 
+0

我认为你的page.tpl文件应该在page.tpl.php中重命名。 我试过你的代码,它似乎与page.tpl.php一起使用。 – lastYorsh

+0

它只是在工程/ oneTimePopupData – user3386779

+0

我试过这两件事情,你需要在'$ items'数组中设置页面参数,其次你通过引用传递'$ edit'。删除'&'将起作用。虽然我建议你阅读https://drupal.stackexchange.com/questions/24135/parameter-expected-to-be-reference-value-given-error-in-menu-page-callback/24139#24139 –

回答

0

希望这有助于你

function one_time_popup_menu(){ 
    $items['popuppage'] = array(
     'title' => 'One time Popup', 
     'page callback' => 'one_time_popup_page', 
     'type' => MENU_CALLBACK, 
     'access arguments' => array('access content'), 
    ); 
    return $items; 
} 

function one_time_popup_page(){ 
    $output = 'value from one time popup module!'; 
    return theme('photo_order',array('results' => $output)); 
} 

function one_time_popup_theme() { 
    $path = drupal_get_path('module', 'one_time_popup'); 
    return array(
     'photo_order' => array(
      'variables' => array('results' => null), 
      'template' => 'photo_order', 
      'path' => $path, 
     ), 
    ); 
} 

将您的TPL文件photo_order .tpl.php在你的模块目录里面,它使用下面的代码。

<?php print $results; ?> 

function one_time_popup_theme() { 
    return array(
     'photo_order' => array(
      'variables' => array('results' => null), 
      'template' => 'photo_order', 
     ), 
    ); 
} 

将您的TPL文件photo_order.tpl.php在你的主题目录和里面下面的代码

<?php print $results; ?> 

去的地方,你的http://yourdomain.com/popuppage看结果。