Thread Rating:
  • 1 Votes - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 PHP in Templates
ZiNgA BuRgA Offline
Fag
*******
Posts: 3,357
Joined: Jan 2008
Post: #1
PHP in Templates
Well, this seems to be requested a bit, and being a rather short plugin, I decided to make it.

Simply, this allows you to enter PHP code in templates, by enclosing it in <?php ?> tags.

For example:

HTML Code
1
2
3
4
5
6
7
8
<!-- template stuff -->
<td>
<?php
if($mybb->user['uid']) echo 'You are logged in.';
else echo 'You are not logged in.';
?>
</td>
<!-- more template stuff -->


Changes in v1.1

  • PHP will now inherit the correct scope of where the code is being eval'd.
  • Also added conditionals in templates
  • Added some function shortcuts

Examples of the above - you might use this in your postbit:

HTML Code
<if $post['fid5'] then>
Your game tag is <func htmlspecialchars_uni>{$post['fid5']}</func>
<elseif $post['fid6'] and $mybb->user['cancp'] then>
This user's lucky number is <func intval>{$post['fid6']}</func>
<else />{$post['fid7']}</if>


Tips:
- PHP will execute slower than template conditionals and function shortcuts, so I recommend using the former unless you need the latter



Attached File(s)
.php  phptpl.php (Size: 2.69 KB / Downloads: 865)

My Blog
(This post was last modified: 05-27-2008 09:01 PM by ZiNgA BuRgA.)
05-03-2008 03:41 PM
Find all posts by this user

« Next Oldest | Next Newest »

Messages In This Thread
PHP in Templates - ZiNgA BuRgA - 05-03-2008 03:41 PM
RE: PHP in Templates - ancraz - 05-04-2008, 11:15 PM
RE: PHP in Templates - ancraz - 05-18-2008, 07:33 PM
RE: PHP in Templates - Guest - 05-18-2008, 09:21 PM
RE: PHP in Templates - grindcore - 05-18-2008, 09:27 PM
RE: PHP in Templates - ZiNgA BuRgA - 05-20-2008, 10:20 AM
RE: RE: PHP in Templates - ancraz - 05-20-2008, 10:33 AM
RE: PHP in Templates - ZiNgA BuRgA - 05-20-2008, 12:23 PM
RE: PHP in Templates - ZiNgA BuRgA - 05-27-2008, 09:00 PM
RE: PHP in Templates - ancraz - 07-20-2008, 04:05 PM

 Standard Tools
Forum Jump: