Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Problem using Template Conditionals
hansolo Offline
Junior Member
**
Posts: 22
Joined: Sep 2015
Post: #1
Problem using Template Conditionals
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!
(This post was last modified: 09-19-2015 01:24 AM by hansolo.)
09-19-2015 01:03 AM
Find all posts by this user Quote this message in a reply
RateU Offline
Administrator
*******
Posts: 2,350
Joined: Mar 2010
Post: #2
RE: Problem using Template Conditionals
It should be in your global.css
09-19-2015 01:34 AM
Find all posts by this user Quote this message in a reply
hansolo Offline
Junior Member
**
Posts: 22
Joined: Sep 2015
Post: #3
RE: Problem using Template Conditionals
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.

(This post was last modified: 09-19-2015 02:23 AM by hansolo.)
09-19-2015 02:22 AM
Find all posts by this user Quote this message in a reply
RateU Offline
Administrator
*******
Posts: 2,350
Joined: Mar 2010
Post: #4
RE: Problem using Template Conditionals
You can find the preference of it in inc/functions_post.php

PHP Code:
642
643
644
645
		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")."\";");
		}

09-19-2015 02:33 AM
Find all posts by this user Quote this message in a reply
hansolo Offline
Junior Member
**
Posts: 22
Joined: Sep 2015
Post: #5
RE: Problem using Template Conditionals
I see. So I should implement this functionality as a plugin then.
09-19-2015 03:18 AM
Find all posts by this user Quote this message in a reply
RateU Offline
Administrator
*******
Posts: 2,350
Joined: Mar 2010
Post: #6
RE: Problem using Template Conditionals
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.
09-19-2015 05:02 AM
Find all posts by this user Quote this message in a reply
hansolo Offline
Junior Member
**
Posts: 22
Joined: Sep 2015
Post: #7
RE: Problem using Template Conditionals
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!

09-19-2015 10:48 PM
Find all posts by this user Quote this message in a reply
RateU Offline
Administrator
*******
Posts: 2,350
Joined: Mar 2010
Post: #8
RE: Problem using Template Conditionals
I hope the example on this page can describe it
http://php.net/manual/en/function.eval.php

09-20-2015 01:49 AM
Find all posts by this user Quote this message in a reply
ZiNgA BuRgA Offline
Fag
*******
Posts: 3,357
Joined: Jan 2008
Post: #9
RE: Problem using Template Conditionals
(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.

My Blog
09-29-2015 12:28 PM
Find all posts by this user Quote this message in a reply

« Next Oldest | Next Newest »

 Standard Tools
Forum Jump: