2017-09-04 143 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看結果。