The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
|||
|
|||
Using vb:raw in templates
Hi, I have create multiple custom pages on my forum. I have a navigation bar on the left of all of said pages. Everytime I add/change a link, I need to go into each and every template to add/change that link.
Is there a way to make a template called "custom_nav", add the links for my nav bar, then call that template from each of the custom pages? If so, can someone help me do it or show me where to start please? Thanks |
#2
|
|||
|
|||
You could use a template. You would need php code to render your template and save the results in a variable, then register that variable to any template where you want to display it. You could do that in a plugin, or if your custom pages are php scripts, you could do it in your custom scripts.
How are your custom pages implemented? |
Благодарность от: | ||
Black Snow |
#3
|
||||
|
||||
|
Благодарность от: | ||
Black Snow |
#4
|
|||
|
|||
Quote:
I have this in my php file. Code:
<?php // ####################### SET PHP ENVIRONMENT ########################### error_reporting(E_ALL & ~E_NOTICE); // #################### DEFINE IMPORTANT CONSTANTS ####################### define('THIS_SCRIPT', 'info'); 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('siterules'); // pre-cache templates used by specific actions $actiontemplates = array(); // ######################### REQUIRE BACK-END ############################ // if your page is outside of your normal vb forums directory, you should change directories by uncommenting the next line // chdir ('/path/to/your/forums'); require_once('./global.php'); // ####################################################################### // ######################## START MAIN SCRIPT ############################ // ####################################################################### $navbits = construct_navbits(array('' => 'Forum')); $navbar = render_navbar_template($navbits); // ###### YOUR CUSTOM CODE GOES HERE ##### //Use as http:/site.com/test.php?do=siterules if ($_REQUEST['do'] == "siterules") { $pagetitle = 'Site Rules'; $templater = vB_Template::create('siterules'); $templater->register_page_templates(); $templater->register('navbar', $navbar); $templater->register('pagetitle', $pagetitle); print_output($templater->render()); exit; } ?> So, I have a template called "siterules", using the PHP file above. I now want to add a navigation bar on this page and a further 4 pages so when I add/change a link, it reflects on all pages. How can I use a plugin to pull the template "navigation" and insert it on each of the custom pages? |
#5
|
|||
|
|||
Well, since you have custom php files you don't need to use a plugin. You can add code to render your custom template before the "main" page template. So just after the "YOUR CUSTOM CODE GOES HERE", add something like:
Code:
$templater = vB_Template::create('custom_nav'); $custom_nav = $templater->render(); Then lower down, add a "register" line to your template code: Code:
$templater->register('custom_nav', $custom_nav); One last thing, for efficiency: add custom_nav to the (existing) array of templates to cache ($globaltemplates): Code:
$globaltemplates = array('siterules', 'custom_nav'); |
#6
|
|||
|
|||
Thanks. I will try that and report back.
--------------- Added [DATE]1409309336[/DATE] at [TIME]1409309336[/TIME] --------------- Quote:
I have one other question. How do I make a page show if there is no Code:
if ($_REQUEST['do'] == BLAH Code:
if ($_REQUEST['do'] == 1 if ($_REQUEST['do'] == 2 if ($_REQUEST['do'] == 3 if ($_REQUEST['do'] == 4 |
#7
|
||||
|
||||
As a rule: You never, ever once address URL parameters directly like that. Opens you up for all kinds of vulnerabilities.
Read and implement: https://vborg.vbsupport.ru/showthread.php?t=119372 After that, you will have your parameter in a nice variable, for example: do. And to your question - if a variable is not defined, you define it in your code. See PHP man isset. Along the lines of Code:
if (!isset($do)) { $do = 1; } Code:
if (!isset($do) OR $do == 1)) |
#8
|
|||
|
|||
So I could do this:
Code:
if (!isset($do) OR $_REQUEST['do'] == 1) |
#9
|
||||
|
||||
Why would you use $_Request again if you have cleaned the input and assigned it to $do? If you havn't done that, $do will not work. And as I said before: Accessing $_REQUEST directly is evil. Do not do it. Read the link I gave you.
This is really basic PHP 101. |
#10
|
|||
|
|||
Your link doesn't show how to use $vbulletin->input->clean_array_gpc when requesting a page. Could you show me an example?
|
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|