MyBB Community Forums

Full Version: PHP in Templates
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,
I liked to use some php in the templates. It seems not to be supported directly. How can I use it anyway?

Thanks
You cannot use PHP in templates except variables. You should use it in plugins or the actual code.
Tikitiki Wrote:You cannot use PHP in templates except variables. You should use it in plugins or the actual code.

Ok, maybe there is a quickndirty solution with variables. How does this work?
Thanks for your help.
read this tutorial it will help I think
http://community.mybboard.net/showthread.php?tid=6615
pepotiger Wrote:read this tutorial it will help I think
http://community.mybboard.net/showthread.php?tid=6615

Thanks, but that's not what I intend to do.
Maybe I just should explain what I plan to do:

I integrated the forum into my page and my page has a horizontal menu at the top, which should be displayed at the forum as well, so you can switch easily between forum and the regular page. But this menu gets more options if you are logged in. Now I need a way to include this menu in the header and differentiate between two status: not logged in and logged in.
Sorry for this second posting.
I think I don't have to do a plugin for that.

Could you please just tell me how/where I define an own variable?

I read somewhere that I just have to put in global.php

$myvariable="test";

and can use it in the template with {$myvariable}

but it doesn't work. So how can I do it (I know I've to change something in the code and have to do it again after updating mybb).?

Thanks for your help!
Yes, you can place it in whatever file you want it to work in (global.php will allow it to work in all files)

However you need to place it ABOVE the call to the template you want it in. So for example if you want to use {$myvariable} in the header template you need to place it above the block of code which fetches the header template (...$templates->get("header")....)
Chris Boulton Wrote:However you need to place it ABOVE the call to the template you want it in. So for example if you want to use {$myvariable} in the header template you need to place it above the block of code which fetches the header template (...$templates->get("header")....)

That worked, thank you Smile