2011-12-07 66 views
0

aboutus.html上的{CONSTANT}如何顯示「Hello world」。我在aboutus.php中定義的?PHPbb傳遞參數或定義參數

很多很多謝謝。

aboutus.php - 我定義常量的hello world。

<?php 
define('IN_PHPBB', true); 
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './'; 
$phpEx = substr(strrchr(__FILE__, '.'), 1); 
include($phpbb_root_path . 'common.' . $phpEx); 

define("CONSTANT", "Hello world."); 

// Start session management 
$user->session_begin(); 
$auth->acl($user->data); 
$user->setup(); 

if ($user->data['user_id'] == ANONYMOUS) 
{ 
    login_box('', $user->lang['LOGIN']); 
} 

page_header('Title Here'); 

$template->set_filenames(array(
    'body' => 'aboutus_body.html', 
)); 

make_jumpbox(append_sid("{$phpbb_root_path}viewforum.$phpEx")); 
page_footer(); 
?> 

aboutus_body.html - 哪有{常數衝顯示的 「Hello World」。上面定義的?

<h2>About Us2</h2> 

<div class="panel"> 
    <div class="inner"><span class="corners-top"><span></span></span> 

    <div class="content"> 
     <p> 
     We were founded this year to bring you the best forum on the Internet! 

     We promise to do the following: 
     <ul> 
      <li>Provide new content</li> 
      <li>provide a friendly atmosphere</li> 
      <li>Provide an environment where you can have fun!</li> 
     </ul> 
     <p>{CONSTANT}</p> 
     </p> 
    </div> 

    <span class="corners-bottom"><span></span></span></div> 
</div> 

回答

2

正如您試圖定義的那樣,模板變量不是傳統的PHP常量。相反,它們使用模板類的assign_var()/ assign_vars()/ assign_block_vars()方法從PHP文件分配給模板。

例如:

<?php 
// assign a single template variable 
$template->assign_var('CONSTANT', 'Hello World'); 
/// assign an array of template variables 
$template->assign_vars(array(
     'CONSTANT' => 'Hello World', 
     'CONSTANT2' => 'Goodbye World', 
)); 
// assign a loop/block 
for($i = 0;....) 
{ 
    $template->assign_block_vars('blockname', array(
      'CONSTANT' => 'Hello World', 
    )); 
} 
?> 

注意模板變量必須是大寫和塊名稱必須是小寫。

你再調用該文件中的變量,像這樣:{CONSTANT} 對於塊:

<!-- BEGIN blockname --> 
{blockname.CONSTANT} 
<!-- END blockname -->