miniBB ® 

miniBB

®
Support Forums
  
 | Start | Register | Search | Statistics | File Bank | Manual |
FAQ miniBB Support Forums / FAQ /  
 

PHP code / variables in templates

 
Author Team
8-)
#1 | Posted: 11 Oct 2006 06:48 
PHP code in templates will not work. Templates are created for separating layout and PHP code, and there could be nothing related to PHP.

But - there is another way to insert dynamic values in templates. As you might see, every template contains {$variable} tags. Each {$variable} means value of 'natural' $variable formed in PHP code.

So, if you want to include your own dynamic content in templates, assign this content to some $variable within your code, then paste {$variable} tag into the template. This code may be generated in bb_plugins.php file, as this is the most common file of all miniBB custom additions.

For example, if in bb_plugins.php we have:

$myDate='Today is '.date('D F jS, Y');

and then paste in templates/main_footer.html

{$myDate}

it will generate today's date like

Wed October 11th, 2006

We hope this gives you enough imagination of how you can add custom PHP output to the templates. Please, address all other custom questions to our paid support team.

Author Anonymous
Guest
#2 | Posted: 12 Oct 2006 15:30 
I also just discovered that you can paste PHP code into the bb_plugin file as a header. Since bb_plugin reacts at the beginning of the script. So I simply inserted and "include" to my header there, and wala!

Author Paul
Lead Developer 
#3 | Posted: 13 Oct 2006 02:17 
Anonymous
I think, it's a bit wrong solution, but if your PHP version runs ok with it - that's ok... Having solution like this, you may experience so called "Headers already sent" error, specially on sign in or posting a message, i.e. each operation which will require redirection header.

Author Anonymous
Guest
#4 | Posted: 24 Feb 2007 17:57 
Hi,
where should i place my code when i wanna call a result like: {$something} in the user_logged_in.html template?

The {$user_usr} shows the username but if i paste my custom text: {$user_comip} it shows nothing at all. At the moment my code for $user_comip is listed in the bb_plugins.php file.

I know the code is correct because when i paste {$user_comip} on the main_forums.html page for example, i see a correct number.

Any idea how i can see the same number in user_logged_in.html file?

Author Paul
Lead Developer 
#5 | Posted: 25 Feb 2007 09:56 
It depends in what file this variable is initialized. In some cases you also may need to initialize it as GLOBAL variable inside the script (specially if it is set in some function).

Author trc4949
Partaker
#6 | Posted: 29 May 2007 11:49 
I am trying to put the following php code:

<?php
CarpConf('cborder','');
CarpConf('iorder','link,date,author,desc');
CarpConf('maxidesc',132);
CarpConf('bidate','<b><i>Posted on ');
CarpConf('aidate','</i></b>');
CarpConf('aidesc','<br><br>');
CarpConf('cacheinterval',60);
CarpConf('poweredby','');
CarpConf('maxitems',5);
?>

at the bottom of the following page to the left of the ad block in the blank space there...

so I put the following within bb_plugins.php right after where my Captcha Authorization addon is located :

$carpfeed=<?php
CarpConf('cborder','');
CarpConf('iorder','link,date,author,desc');
CarpConf('maxidesc',132);
CarpConf('bidate','<b><i>Posted on ');
CarpConf('aidate','</i></b>');
CarpConf('aidesc','<br><br>');
CarpConf('cacheinterval',60);
CarpConf('poweredby','');
CarpConf('maxitems',5);
?>

and then I put {$carpfeed} in a table to the left of the ad block at the bottom of the page within main_posts.html

but for some reason when I go to:


it displays the feed at the top of the page and not where I have the
{$carpfeed} at the bottom of the page.

thoughts ?

Tom

Author Paul
Lead Developer 
#7 | Posted: 29 May 2007 12:19 
That is probably because CarpCacheShow() function echoes the code on the page. But it must store the output in the variable and not echo it.

You may use ob_start() related functions to store output in the variable. Like

ob_start();
require_once '/var/www/bestonlinetrades/carp/carp.php';
//...your code...
CarpCacheShow('http://forums.bestonlinetrades.com/rss2.php');
$carpfeed=ob_get_contents();
ob_end_clear();

Author trc4949
Partaker
#8 | Posted: 29 May 2007 14:51 
well that did nto seem to work...

here is the entire contents of my bb plugins file and is exactly what it looks like:

<?php
if (!defined('INCLUDED776')) die ('Fatal error.');
/* Captcha Authorization addon */

/* --Captcha Authorization addon */
?>
ob_start();
CarpConf('cborder','');
CarpConf('iorder','link,date,author,desc');
CarpConf('maxidesc',132);
CarpConf('bidate','<b><i>Posted on ');
CarpConf('aidate','</i></b>');
CarpConf('aidesc','<br><br>');
CarpConf('cacheinterval',60);
CarpConf('poweredby','');
CarpConf('maxitems',5);
$carpfeed=ob_get_contents();
ob_end_clear();



Did I put it in bb_plugins correctly?

tom

Author Paul
Lead Developer 
#9 | Posted: 30 May 2007 03:24 
I don't understand why you put this code outside PHP bracket ?>...

Please do never publish any of the commercial addons code, it is prohibited by the license, paid addons are not released as open source; additionally, you're violating our forum rules, since you're posting about the problem which is your own. I have explained what do you need to do; I am not going to explain anymore further, it's our paid support task.

Author MyFairTux
Partaker
#10 | Posted: 4 Jan 2008 04:19 
I want to not show the menu bar in my polls list.

So I modified main_header.html, inserted a new variable {$menubar} an moved the whole HTML part of the menu into this variable.

Well, it doesn't work as wished because the replacing of the vars is done only once and I got a menu bar with the old variable names visible.

Is there a way to parse my new variable text before the finally parse of minibb, so all menu entries appear correct? (like a kind of a 2-stage recursion)

Regards,
Christoph

P.S.: a quick and dirty solution was to "comment out" the menu bar HTML code by setting "<!--" and "-->" with two new variables before and after - but that's really ugly ;-)

Author Paul
Lead Developer 
#11 | Posted: 5 Jan 2008 06:12 
I suppose you need to refer to $includeHeader variable and so create a special PHP header where you will handle $action=='polls' condition.

Please refer to this thread for more on how to handle PHP variables inside a custom header (miniBB menu variables need to be defined as $GLOBAL's and other probably too):

https://www.minibb.com/forums/2_4058_0.html

FAQ miniBB Support Forums / FAQ /
 PHP code / variables in templates
 Share Topic's Link

Your Reply Click this icon to move up to the quoted message


  ?
Post as a Guest, leaving the Password field blank. You could also enter a Guest name, if it's not taken by a member yet. Sign-in and post at once, or just sign-in, bypassing the message's text.


Before posting, make sure your message is compliant with forum rules; otherwise it could be locked or removed with no explanation.

 

 
miniBB Support Forums Powered by Forum Software miniBB ® Home  Features  Requirements  Demo  Download  Showcase  Gallery of Arts
Compiler  Premium Extensions  Premium Support  License  Contact Us
Try the Private Messaging add-on: allow your miniBB-forums members to communicate with each other.


  ⇑