开发者

vBulletin 4.0 custom pages

I'm trying to make custom pages using the new vBulletin 4.

My PHP file uses the code below:

$templater = vB_Template::create('TEST');
$templater->register_page_templates();
$templater->register('navbar', $navbar);
$templater->register('pagetitle', $pagetitle);
print_output($templater->render());

My template looks like this:

{vb:stylevar htmldoctype}
<html xmlns="http://www.w3.org/1999/xhtml" dir="{vb:stylevar textdirection}" lang="{vb:stylevar languagecode}" id="vbulletin_html">
  <head>
    <title>{vb:raw vboptions.bbtitle} - {vb:raw pagetitle}</title>
    {vb:raw headinclude}
    {vb:raw headinclude_bottom}
  </head>
  <body>

    {vb:raw header}

    {vb:raw navbar}

    <div id="pagetitle">
      <h1>{vb:raw pagetitle}</h1>
    </div>

    <h2 class="blockhead">Title</h2>
    <div class="blockbody">
      <div class="blockrow">
        Text
      </div>
    </div>

    {vb:raw footer}
  </body>
</html>

My question relates to the use of one single template for around 50 pages, which used HTML and PHP together and were workin开发者_如何转开发g in vBulletin 3.

Will I need to use a separate template for each custom page that I make from the existing pages?

EDIT 1: I've opened a BOUNTY worth 100 points for this question. If you need any more details on my question, please leave a comment.

EDIT 2: Originally, I was using eval('$mytemplate = "' . fetch_template('mytemplate') . '";'); using vB3. This has broken the pages in vB4. If I follow ARandomOWI's post, will I be following the best approach?


You can use the same template for all your custom pages if you only want to change some of the content between them.

In your PHP file you can pass variables to your template using:

$templater->register('var_name_used_in_template', $your_php_var);

This needs to be included before the "print_output" line. Then in your template you can add:

{vb:var var_name_used_in_template}

To display the contents of the variable "$your_php_var" that existed in the PHP.

This way you can use "$your_php_var" to store some HTML to be displayed within your template. You can split the content between multiple PHP files or use a single file for all the content and use PHP conditionals to alter "$your_php_var".

Note: variables passed with "vb:var" are first put through the function "htmlspecialchars_uni()". If this causes problems, you can use "vb:raw" instead which passes the raw variable. Although, be sure that the variable has already been sanitized within the PHP file.

Hope that's clear enough.


@Jon: If you already have all the templates and PHP files setup from the VB3 version, you can replace the

eval('$mytemplate = "' . fetch_template('mytemplate') . '";');

with

$templater = vB_Template::create('mytemplate');
$templater->register_page_templates();
$templater->register('navbar', $navbar);
$templater->register('pagetitle', $pagetitle);
print_output($templater->render());

If I understand correctly. You may wish to alter the "pagetitle" and "navbar" variables. How you go about it depends on what you are working with. (Whether you are trying to make existing code work, or start from scratch.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜