PHPbb传递参数或定义参数

时间:2011-12-07 07:29:36

标签: phpbb phpbb3

在aboutus.html上{CONSTANT}如何显示“Hello world”。我在aboutus.php定义了什么?

非常感谢。

aboutus.php - 我已将CONSTANT定义为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 - 如何{CONSTANT}显示“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>

1 个答案:

答案 0 :(得分: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 -->