MyBB Hacks

Full Version: Problem using Template Conditionals
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi All,

I've just installed the 'template conditionals' plugin. I want to use it to display certain buttons only on the first post of a thread, in a new bar just above the Post Controls bar.

My code, which I've added to the sub-forum postbit template, looks like:

Code:
<if($mybb->post['replyto'] == "0") then>
	<div class="special_controls">
		<span>SPECIAL CONTROLS WILL GO HERE</span>
	</div>
</if>


My browser says "Content Encoding Error" when I try to open this page. Why is this?

Also is this the right way to implement this functionality, or is there a better way that keeps functional code out of the templates?

Cheers!


Turns out it's whitespace sensitive. Needs to be:

Code:
<if ($post[...


I do have one more question:
Where is the 'post_controls' class assigned its layout? Is it in a .css file or in the template somewhere? I tried a full directory search and couldn't find it.

Cheers!
It should be in your global.css
Thanks, yes I ended up finding it in the 'themes' section, it seems to be another 'code in database' thing, unless I've understood something wrong.

Anyway, I'm now wracking my brain with this: How is

Code:
$post['button_quote']

assigned? These appear to be used in the templates to import other templates into themselves.

You can find the preference of it in inc/functions_post.php

PHP Code:
		if($forum['open'] != 0 && ($thread['closed'] != 1 || is_moderator($forum['fid'], "canpostclosedthreads")) && ($thread['uid'] == $mybb->user['uid'] || $forumpermissions['canonlyreplyownthreads'] != 1))
		{
			eval("\$post['button_quote'] = \"".$templates->get("postbit_quote")."\";");
		}

I see. So I should implement this functionality as a plugin then.
BTW, for first post condition, you can try using $postcounter variable.

If you want a complex different layout for the first post, if you use XThreads, you can create postbit_first* template(s), which will apply to the first post only.
Oh OK thanks. I might use that, but there is a possibility I will reuse this control bar in later posts in a thread (i.e. reshowing it and changing its buttons), so I think the plugin is the safest bet.

I do have a question about the use of eval in the above example:

Code:
eval("\$post['button_quote'] = \"".$templates->get("postbit_quote")."\";");


Maybe I'm having a mental blank, but why isn't it just written as:

Code:
$post['button_quote'] = $templates->get("postbit_quote");

?

Cheers!

I hope the example on this page can describe it
http://php.net/manual/en/function.eval.php
(09-19-2015 10:48 PM)hansolo Wrote: [ -> ]Maybe I'm having a mental blank, but why isn't it just written as:

Code:
$post['button_quote'] = $templates->get("postbit_quote");

?

That behaves differently.  The template code actually needs to be evaluated (it's how stuff like {$blah} get transformed) - if you try your code, you'll notice that tokens don't get replaced.
Reference URL's