vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vBulletin 4 Articles (https://vborg.vbsupport.ru/forumdisplay.php?f=242)
-   -   [HOW TO - vB4] Rendering templates and registering variables - a short guide (https://vborg.vbsupport.ru/showthread.php?t=228078)

testebr 11-18-2009 07:54 PM

I figure out how to solve it:

hook: process_templates_complete

code: $footer .= 'text added to footer';

No idea if was the best solution, but that worked very well.

cellarius 11-18-2009 08:13 PM

1 Attachment(s)
Quote:

Originally Posted by testebr (Post 1916821)
hook: process_templates_complete

code: $footer .= 'text added to footer';

Indeed, you can manipulate the already rendered template doing this. Also possible is str_replace:
PHP Code:

$search "Terms of Service";
$replace "Terms of Cooking Noodles";
$footer str_replace($search,$replace,$footer); 

Although this is a somewhat bad example, since "Terms of Service" is a phrase, of course, and will vary by language. Always make sure you use strings for replacement that are always present.

Attachment 106372

Using str_replace, you can also add stuff in the middle of the template like so:
PHP Code:

$search "Terms of Service";
$replace " and Terms of Cooking Noodles";
$footer str_replace($search,$search.$replace,$footer); 

Attachment 106374

David Regimbal 11-19-2009 07:26 PM

Hi,

I'm trying to add something that requires PHP under the navbar. Back in vb 3.8.x I just used plugins for this. But, I'm not sure which hook to use if I want to display something under the navbar.

cellarius 11-20-2009 10:19 AM

@David: This is not related to the topic of this article. You should open your own thread on this..

Also, I just added the bonus track about template caching.

ragtek 11-20-2009 03:02 PM

Quote:

Originally Posted by cellarius (Post 1917658)
@David: This is not related to the topic of this article. You should open your own thread on this..


Also, I just added the bonus track about template caching.

Sure?
It's $cache[] = 'xxx'; and not $globaltemplate now;) ;)

cellarius 11-20-2009 03:10 PM

Ah, damn, of course you're right. I had my example code for vB3 and the one I was about to change for vB4 side by side and then obviously copied/pasted the wrong one. Stupid me :)

ragtek 11-20-2009 03:19 PM

Quote:

Originally Posted by cellarius (Post 1917809)
Ah, damn, of course you're right. I had my example code for vB3 and the one I was about to change for vB4 side by side and then obviously copied/pasted the wrong one. Stupid me :)

Yea, i know.
I made the mistake in all my add-ons on porting them to vB4:D

EidolonAH 11-22-2009 12:15 AM

Thanks for the "cache your templates" info, I made use of this info after making my own Terms of Service and Privacy custom pages, very helpful, thank you.:up:

Zaiaku 11-27-2009 09:13 PM

Quote:

Originally Posted by cellarius (Post 1916832)
Indeed, you can manipulate the already rendered template doing this. Also possible is str_replace:
PHP Code:

$search "Terms of Service";
$replace "Terms of Cooking Noodles";
$footer str_replace($search,$replace,$footer); 

Although this is a somewhat bad example, since "Terms of Service" is a phrase, of course, and will vary by language. Always make sure you use strings for replacement that are always present.

Attachment 106372

Using str_replace, you can also add stuff in the middle of the template like so:
PHP Code:

$search "Terms of Service";
$replace " and Terms of Cooking Noodles";
$footer str_replace($search,$search.$replace,$footer); 

Also can this be used on variables? ex: {vb:raw variable}

Attachment 106374

OK I'm trying to do the same thing but on showthread, from this example is $footer a var already being used of is this an additional variable made up int he plugin? Right now I'm using $vbulletin->templatecache['postbit'] with the <hookname>process_templates_complete, should this something diffrent?

<hookname>showthread_query</hookname>
$vbulletin->templatecache['postbit'] = str_replace($find, $replace, $vbulletin->templatecache['postbit']);

Also can this be used on variables? ex: {vb:raw variable}

jlevi 12-01-2009 06:42 PM

This isn't working for me. I'm probably doing something wrong, but at the moment I have a custom php page (I created following another tutorial elsewhere) that is calling a custom template.

The code for the php page:
PHP Code:

<?php 

// ####################### SET PHP ENVIRONMENT ########################### 
error_reporting(E_ALL & ~E_NOTICE); 

// #################### DEFINE IMPORTANT CONSTANTS ####################### 

define('THIS_SCRIPT''test'); 
define('CSRF_PROTECTION'true);   
// change this depending on your filename 

// ################### PRE-CACHE TEMPLATES AND DATA ###################### 
// get special phrase groups 
$phrasegroups = array(); 

// get special data templates from the datastore 
$specialtemplates = array(); 

// pre-cache templates used by all actions 
$globaltemplates = array('TESTPAGE'
); 

// pre-cache templates used by specific actions 
$actiontemplates = array(); 

// ######################### REQUIRE BACK-END ############################ 
require_once('./global.php'); 

// ####################################################################### 
// ######################## START MAIN SCRIPT ############################ 
// ####################################################################### 

$navbits construct_navbits(array('' => 'Test Page')); 
$navbar render_navbar_template($navbits); 

// ###### YOUR CUSTOM CODE GOES HERE ##### 
$pagetitle 'My Page Title'

// ###### NOW YOUR TEMPLATE IS BEING RENDERED ###### 

$templater vB_Template::create('TESTPAGE'); 
$templater->register_page_templates(); 
$templater->register('navbar'$navbar); 
$templater->register('pagetitle''Test Page'); 
print_output($templater->render()); 

?>


And the HTML template (called TESTPAGE):
HTML Code:

{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}</title>
    {vb:raw headinclude}
  </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>

And the plugin in global_start:
PHP Code:

$templater vB_Template::create('TESTPAGE'); 
print_output($templater->render()); 


Where have I gone wrong? I've spent a good half an hour going through the tutorial and trying various things but can't seem to get it working. It always makes the whole site blank, but if I call another template (e.g. contactus instead of TESTPAGE) it works fine, so the problem seems to lie with the plugin.

Any help greatly appreciated - thanks in advance :)


All times are GMT. The time now is 03:09 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01664 seconds
  • Memory Usage 1,775KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_html_printable
  • (6)bbcode_php_printable
  • (4)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (4)pagenav_pagelink
  • (1)pagenav_pagelinkrel
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete