MyBB Community Forums
PHP in Templates and Template Conditionals - Printable Version

+- MyBB Community Forums (https://community.mybb.com)
+-- Forum: Extensions (https://community.mybb.com/forum-201.html)
+--- Forum: Plugins (https://community.mybb.com/forum-73.html)
+---- Forum: Plugin Support (https://community.mybb.com/forum-72.html)
+---- Thread: PHP in Templates and Template Conditionals (/thread-31860.html)

Pages: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20


PHP in Templates and Template Conditionals - Yumi - 2008-05-27

This is a relatively small plugin, but seems that a number of people wanted such a thing, so... here it is.

This plugin will allow you to use:
  • PHP in templates, using <?php ... ?> tags
  • Shortcut template conditionals, using <if ... then>...<elseif ... then>...<else>...</if>
  • Some shortcut string functions (see below), eg <func htmlspecialchars>...</func>
  • Call another template, using <template ...>, eg <template header>


Here's an example of some of the functions that this can be used for - for example, you may use this code in your postbit:

{$post['user_details']}

<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 />Some other profile field: {$post['fid7']}</if>

<?php echo "Hi from PHP"; ?>


More info & Download
(it's easier to keep one location up to date Toungue)


RE: PHP in Templates and Template Conditionals - mybbromania - 2008-05-27

Huh... this is very useful.

// We can insert javascript code in templates... so, why not some php code ?
Thank you so much. Smile

//Later: I think this should be included in the 1.4 version.


RE: PHP in Templates and Template Conditionals - aglioeolio - 2008-05-27

amazing Release Big Grin

Thanks Zinga


RE: PHP in Templates and Template Conditionals - labrocca - 2008-05-27

So this works without any hooks?


RE: PHP in Templates and Template Conditionals - Yumi - 2008-05-28

labrocca Wrote:So this works without any hooks?
Explicitly, no.

Gaining control of objects is a way to implicitly get "hooks".


RE: PHP in Templates and Template Conditionals - labrocca - 2008-05-28

I suck at objects..I just spent the day working on them though and learned a few things. I hope to be gain better OOP knowledge this upcoming year. It's the future of php of course.

Thanks for response Zinga.


RE: PHP in Templates and Template Conditionals - TStarGermany - 2008-05-31

thx zinga, you're beating one of the biggest weaknesses in mybb with this...


RE: PHP in Templates and Template Conditionals - jnd52 - 2008-08-15

Great Plugin! I have found it every useful.


RE: PHP in Templates and Template Conditionals - Yumi - 2008-08-17

eval does run slower, primarily due to the fact that it can't precompile/cache the PHP code, but since all of this is eval'd anyway, it's not too much of a difference. eval does cause some overhead when you put an extra layer on it though. Also, ob_* functions are used, which isn't the most efficient either.

This plugin is mainly for convenience purposes. As stated, if someone does manage to gain access to the AdminCP (or modify the templates table), they've got the ability to execute arbitrary code. Plus it's recommended to stick PHP in the .php files rather than templates (for speed and security).


RE: PHP in Templates and Template Conditionals - Hime - 2008-11-01

How to put specific chunk of code....say "Test:Test" using gid & conditionals!?

Can I actually use GID in templates?