MyBB Community Forums

Full Version: eval's and error();
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm trying to create this small mod for my forum. What I need to do is incorporate the error(); function into it, but when it does show the error(); function, I need it to show a template I have created to have a customised error message (as it has the login box into it).

I was wondering, how can I incorporate the error(); function to show off a custom template that I have created into it?
I dont have time to write a full thing or test, so you'll have to adapt this. In global, put this:
$error = error();
if($error) {
eval template call with name say error
}
then in the admin cp, have a template called error, and the contents
template top
$error
template bottom
then whenever error() is used, it will show your template. Hope this works since I havn't been able to test! Enjoy.
No, that won't work because there is already an error template.

What cory needs is something like:

eval("\$blah = \"".$templates->get("template_name_here")."\";");
error($blah);

That should work..
Thats it, Chris's way seems to work. But I when I do that, I just get the template but it's all in white and absolutely has no structure of the forums.
Whats you template coding?? Have you got the basic structure in it??
<html>
<head>
<title>$settings[bbname]</title>
$headerinclude
</head>
<body>
$header
<table border="0" cellspacing="$theme[borderwidth]" cellpadding="$theme[tablespace]" class="tborder"><thead><tr>

<td>Error message here</td>

</tr></thead></table>
$footer
</body>
</html>
All I'm trying to do is show the login box if you're logged out but when i do its STILL white even after using your code k776.
Are you doing this inside a funciton? If so you'll need to declare the variables ($theme for example) as global ones in that function.

Show me the exact code, and the exact template you're using.. Smile
first I made a new settign in the admincp named "disableview". Then I opened up global.php (the one at the forums root) and placed this code

if($settings['disableview'] == "yes")
{
	if($mybbgroup[usergroup] = "1")
	{
	eval("\$disableview = \"".$templates->get("error_disable_view")."\";");
	error($disableview);
	}
}

I made up a new template called "error_disable_view" and place this code on that template (just a login code taken from "error_nopermission" template...not customized yet)

<html>
<head>
<title>$settings[bbname]</title>
$headerinclude
</head>
<body>
$header
<table border="0" cellspacing="$theme[borderwidth]" height="100%" cellpadding="$theme[tablespace]" class="tborder">
<thead>
$loginform
</thead>
</table>
$pms
<p>
<table border="0" cellspacing="$theme[borderwidth]" cellpadding="$theme[tablespace]" class="tborder">
<thead>
<tr>
<td class="thead" width="2%">&nbsp;</td>
<td class="thead" width="59%"><strong>$lang->forumbit_forum</strong></td>
<td class="thead" width="7%" align="center" nowrap="nowrap"><strong>$lang->forumbit_threads</strong></td>
<td class="thead" width="7%" align="center" nowrap="nowrap"><strong>$lang->forumbit_posts</strong></td>
<td class="thead" width="15%" align="center"><strong>$lang->forumbit_lastpost</strong></td>
</tr>
</thead>
$forums
</table>
<table border="0" cellspacing="$theme[borderwidth]" cellpadding="$theme[tablespace]" class="tborder">
<thead>
<tr>
<td class="thead">
<div class="expcolimage"><a href="javascript:expandCollapse('boardstats');"><img src="images/collapse$collapsedimg[boardstats].gif" 
id="boardstats_collapseimg" border="0" alt="[-]" /></a></div>
<div><strong><i>&raquo;</i> $lang->boardstats</strong></div>
</td>
</tr>
</thead>
<br>
<br>
<tbody style="$collapsed[boardstats_e]" id="boardstats_e">
$whosonline
$birthdays
$forumstats
</tbody>
</table>
</td>
</table>
</td></tr>
</table>
</td></tr>
</table>
$footer
</body>
</html>

the variable $disableview should be in there somewheres (or i will place it there later on).

What I want to do is if I turned the setting "disableview" on my admin cp, it will give out an error message with that template. As before, I just did the eval code and all it did was show the "error_disable_view" template at wherever I placed the $disableview variable at.
if im not mistaken, you dont need error for this. Turning
if($settings['disableview'] == "yes")
{
if($mybbgroup[usergroup] = "1")
{
eval("\$disableview = \"".$templates->get("error_disable_view")."\";");
error($disableview);
}
}
into
if($settings['disableview'] == "yes")
{
if($mybbgroup[usergroup] == "1")
{
eval("\$disableview = \"".$templates->get("error_disable_view")."\";");
outputpage($disableview);
}
}
and possibly even:
if($settings['disableview'] != "no" && $mybbgroup[usergroup] == "1") {
eval("\$disableview = \"".$templates->get("error_disable_view")."\";");
outputpage($disableview);
}
Yes.

Note that the error() function already calls the template called 'error' which contains the page headers/footers and all. All you're expected to send to the error function is an error message or html to be contained within the table that the error messages are shown in - no <html> <head> <body> etc.

Chris