PHPbb 传递参数或定义参数

发布于 2024-12-19 23:03:10 字数 1627 浏览 3 评论 0原文

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>

How can {CONSTANT} at the aboutus.html can display "Hello world." which i defined at aboutus.php ?

Many Many Thanks.

aboutus.php - I have define CONSTANT to 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 - how can {CONSTANT} display "Hello World." that defined above?

<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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

说不完的你爱 2024-12-26 23:03:10

您尝试定义的模板变量不是传统的 PHP 常量。相反,使用模板类的 allocate_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 -->

Template variables, as you are trying to define, are not traditional PHP Constants. Instead, they are assigned to the template from the PHP file using the template class's assign_var()/assign_vars()/assign_block_vars() methods.

For instance:

<?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',
     ));
}
?>

Note that template variables must be UPPERCASE, and block names must be lowercase.

You then call the variable in the file like so: {CONSTANT}
For a block:

<!-- BEGIN blockname -->
{blockname.CONSTANT}
<!-- END blockname -->
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文