MyBB Community Forums

Full Version: Including a file in a template
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I want to include a .php file in a template in mybb but it doesn't work, I'm using:
<?include ('The file')?>
What's wrong?
You can't do it. Instead use an iframe. The templates won't execute PHP code in the same manner. If you save your file as a .php then iframe it into the template you should be fine.
How do I iframe / what is it?
Yuck, don't use an iframe, basically this is what you want to do. http://community.mybboard.net/showthread...0#pid26480
Depending on what's in the included file, this should work.
ob_start();
require_once "path/to/some_file.php";
$var = ob_get_clean();

Place that code in the desired MyBB php file, then use {$var} in the template.
All I need to do is include a Text file that contains all of the links. This code isn't working. Well actually I'm probably doing it wrong.

Edit: AHH this really messed my forum up! What do I do?
http://www.bmestudioz.com/community

Edit: I fixed it but I still don't know how to do this. I especially don't know where to put the code, I don't know what file needs to have it.
If you want to want to add it to all pages then you should add it to global.php.

However instead of editing the files, because they may get overwritten when you upgrade to newer versions, I'd recommend using a simple plugin to do the job for you.

Download the attached file, open it up and change "path/to/file.php" to the path of the file you want to include (if you can't figure it out let me know the URL of your text file and I'll fix it up for you).

Then upload the file to your inc/plugins/ directory and go to the "Plugins" page in the Admin CP and click activate next to "Site Navigation Include Plugin".

Then open up the header template (or the template wherever you want the links) and add {$my_navigation} to it - it should appear in the pages.

Basically using a plugin means that when you upload a new version of MyBB with the global.php file changed (or any other file changed) you do not need to redo your changes to the files.
Your the best Chris!
Nice tip.
Can we add adsense code in this php file?
I'm not familiar with Adsense code, but if it requires PHP, then you can put it in a PHP file, and put that filename in the NAV_FILE constant in the plugin file Chris posted.

If the Adsense code doesn't need PHP (which I don't think it does) then you can add the HTML code directly into the template.