MyBB Community Forums

Full Version: {These things}
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Can someone tell me how to use these {example} in something like a html template so that the {example} will be replaced with content via PHP.
Thanks.
Use Smarty or write your own template parser.

Edit: Or do you require help with regex / algorithms to do that replacement?
Asad_Niazi Wrote:Edit: Or do you require help with regex / algorithms to do that replacement?
That one. Like how in mybb you add {toplinks} into the template.
You could add the variable on your global.php file. Example,

Go to the end of Global.php and add this:

$message = "Hello World!";

Then add {$message) in any of your templates, and you will see "Hello World!"
Ok, so if i have an index.php and it says $content = "whatever" and then the page includes the template.html file and within the template.html file it says {$content} that will work?
Wheel-World Wrote:Ok, so if i have an index.php and it says $content = "whatever" and then the page includes the template.html file and within the template.html file it says {$content} that will work?

Nope. You can always add this to your .htaccess file to get php to be parsed in html files:


RemoveHandler .html .htm
AddType application/x-httpd-php .php .htm .html
How does mybb do it?
Wheel-World Wrote:Ok, so if i have an index.php and it says $content = "whatever" and then the page includes the template.html file and within the template.html file it says {$content} that will work?

No, you put it in global.php. At the end of the file, assign your code to a variable, and then on any template you can add it by putting the name of the variable in between {}
DCR Wrote:No, you put it in global.php. At the end of the file, assign your code to a variable, and then on any template you can add it by putting the name of the variable in between {}
I am not talking about within mybb, i am saying how do you do it for other projects.
I thought some staff member would answer this question, oh well.

MyBB stores the templates in the database so it uses something to cover up the real php variables like the {$blah}. The MyBB template system is complex but you can do something similar using the Smarty template system or using eval(), what MyBB uses.
Pages: 1 2