MyBB Community Forums

Full Version: Check if template exists? [HELP]
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hey everyone,

I'm writing a script for someone. Nothing too fancy. But what I'd like to know is if there is a function to check if a template exists in MyBB, and if not, a few pointers to writing a function to do this, as in:
function("templatename");
with a boolean result regarding the template's existance.

Thanks in advance,
michaelh
Just query the database?

return $db->fetch_array($db->simple_select('templates', 'tid', 'title="mytemplate" AND sid>0'));

Not sure if the above is what you want - you'll have to play around a bit with that.
(2008-10-19, 10:59 PM)ZiNgA BuRgA Wrote: [ -> ]Just query the database?

return $db->fetch_array($db->simple_select('templates', 'tid', 'title="mytemplate" AND sid>0'));

Not sure if the above is what you want - you'll have to play around a bit with that.

Using that gives me the following:
Quote:Fatal error: Call to a member function fetch_array() on a non-object
Have you included MyBB's core?

<?
define('IN_MYBB', 1);
chdir('./forums');
require './inc/init.php';

// do your stuff here
$db->whatever
Being an actual page, I included the global.php file. Do I still need to call init if I've done this?
Yes as init.php instantiates $db object. Wink
global.php includes init for you.

If you've included that $db code sample in a function, don't forget to add the line:
global $db;
since it's stored in the global scope.