Why won't lang entry show in sub-template?
hansolo Offline
Junior Member
**
Posts: 22
Joined: Sep 2015
Post: #1
Why won't lang entry show in sub-template?
Hi All,

I'm still working on my modification using xthreads. I am adding a new button to the postbit.

The new button template is called 'cheese_postbit_A' and looks like this:

Code:
<a href="#" title="{$lang->cheese_postbit_A}" class="cheese_postbit_A"><span>{$lang->cheese_postbit_button_A}</span></a>


All of those lang entries are in global.lang.php, the same as the other "button_" entries.

I have a plugin which populates the post member. It executes the following via the postbit hook:

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


$post['button_cheese_A'] is then used in the parent 'postbit_classic' template to show the button.

The problem is: the button shows, but the text is blank. If I manually change the <span> to contain "TEST", then it shows the text "TEST". So the lang member is not being read.

What am I missing?

Cheers!

(This post was last modified: 10-10-2015 09:24 PM by hansolo.)
10-10-2015 09:22 PM
Find all posts by this user Quote this message in a reply
leefish Offline
Hamster
*****
Posts: 1,009
Joined: Apr 2010
Post: #2
RE: Why won't lang entry show in sub-template?
The title and the span are not the same string. Was that intentional? do either show?


[Image: leelink.gif]
MYBB1.6 & XThreads
10-10-2015 09:27 PM
Visit this user's website Find all posts by this user Quote this message in a reply
hansolo Offline
Junior Member
**
Posts: 22
Joined: Sep 2015
Post: #3
RE: Why won't lang entry show in sub-template?
(10-10-2015 09:27 PM)leefish Wrote:  The title and the span are not the same string. Was that intentional? do either show?

No neither show. Title seems to be the tag that shows on mouseover. I just copied the way the 'quote' button works.

Code:
<a href="newreply.php?tid={$tid}&amp;replyto={$post['pid']}" title="{$lang->postbit_quote}" class="postbit_quote"><span>{$lang->postbit_button_quote}</span></a>

10-10-2015 10:29 PM
Find all posts by this user Quote this message in a reply
RateU Offline
Administrator
*******
Posts: 2,350
Joined: Mar 2010
Post: #4
RE: Why won't lang entry show in sub-template?
Sorry if I still don't understand what you did.
The custom language strings also not displayed in the default postbit/_classic template?

10-11-2015 01:26 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: Why won't lang entry show in sub-template?
Yes, so what I'm basically doing is trying to copy exactly how the 'quote' button is implemented, except for what that button does.

In the postbit_classic template:

Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
{$ignore_bit}
<a name="pid{$post['pid']}" id="pid{$post['pid']}"></a>
<div class="post classic {$unapproved_shade}" style="{$post_visibility}" id="post_{$post['pid']}">
<div class="post_author scaleimages">
	{$post['useravatar']}
	<div class="author_information">
			<strong><span class="largetext">{$post['profilelink']}</span></strong> {$post['onlinestatus']}<br />
			<span class="smalltext">
				{$post['usertitle']}<br />
				{$post['userstars']}
				{$post['groupimage']}
			</span>
	</div>
	<div class="author_statistics">
		{$post['user_details']}
	</div>
</div>
<div class="post_content">
	<div class="post_head">
		{$post['posturl']}
		{$post['icon']}
		<span class="post_date">{$post['postdate']} <span class="post_edit" id="edited_by_{$post['pid']}">{$post['editedmsg']}</span></span>
	{$post['subject_extra']}
	</div>
	<div class="post_body scaleimages" id="pid_{$post['pid']}">
		{$post['customrep']}{$post['message']}
	</div>
	{$post['attachments']}
	{$post['signature']}
	<div class="post_meta" id="post_meta_{$post['pid']}">
		{$post['iplogged']}{$post['ratemf']}
	</div>
</div>
<div style="{$post['tyl_display']}" id="tyl_{$post['pid']}">{$post['thankyoulike_data']}</div>
<div class="post_controls">
	<div class="postbit_buttons author_buttons float_left">
		{$post['button_email']}{$post['button_pm']}{$post['button_www']}{$post['button_find']}{$post['button_rep']}
	</div>
	<div class="postbit_buttons post_management_buttons float_right">
		{$post['button_tyl']}{$post['button_edit']}{$post['button_quickdelete']}{$post['button_quickrestore']}{$post['button_quote']}{$post['button_multiquote']}{$post['button_report']}{$post['button_warn']}{$post['button_purgespammer']}{$post['button_reply_pm']}{$post['button_replyall_pm']}{$post['button_forward_pm']}{$post['button_delete_pm']}
	</div>
</div>
</div>


Example sub-template, postbit_quote :

Code:
<a href="newreply.php?tid={$tid}&amp;replyto={$post['pid']}" title="{$lang->postbit_quote}" class="postbit_quote"><span>{$lang->postbit_button_quote}</span></a>


So it's using these members of $post, such as $post['button_quote']. They are in turn populated by "eval"ing templates in functions_post.php.
E.g.:

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")."\";");
		}



So I'm populating my $post['button_cheese_A'] with

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

, in a function added with add_hook("postbit"...

That "cheese_postbit_A" template is being evaluated OK if I hard-code the text. If I try to use my lang-> variables, which are in global.lang.php just the same as the 'button_quote' ones, it just goes blank.

10-11-2015 02:36 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: Why won't lang entry show in sub-template?
Did you global the $lang variable in your plugin?

10-11-2015 02:51 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: Why won't lang entry show in sub-template?
OK thanks that fixed it.
I thought something 'above' the plugin would already be loading the $lang. Still getting the hang of this.
10-11-2015 06:23 PM
Find all posts by this user Quote this message in a reply
ZiNgA BuRgA Offline
Fag
*******
Posts: 3,357
Joined: Jan 2008
Post: #8
RE: Why won't lang entry show in sub-template?
(10-11-2015 06:23 PM)hansolo Wrote:  I thought something 'above' the plugin would already be loading the $lang.
That is correct.
You should review how PHP handles variable scoping in functions: http://php.net/manual/en/language.variables.scope.php

My Blog
10-29-2015 11:35 AM
Find all posts by this user Quote this message in a reply

« Next Oldest | Next Newest »

 Standard Tools
Forum Jump: