Page 1 of 1
Display user's rank on index with template variable
Posted: Mon Mar 11, 2019 12:43 am
by teebling
Hello,
Just a quick request - any way to use a template variable like {RANK_IMG} in overall_header.html?
Teebling
Re: Display user's rank on index with template variable
Posted: Mon Mar 11, 2019 1:45 am
by Lumpy Burgertushie
why? please explain exactly what you are trying to accomplish.
which user? where? etc.
robert
Re: Display user's rank on index with template variable
Posted: Mon Mar 11, 2019 11:09 am
by teebling
Lumpy Burgertushie wrote: ↑Mon Mar 11, 2019 1:45 am
why? please explain exactly what you are trying to accomplish.
which user? where? etc.
robert
Hi Robert,
There is a template variable in phpBB called {RANK_IMG}. When used in a template, it displays the current user’s rank image.
It is used in template files like viewtopic_body.html (viewing the posts of a topic) and memberlist_view.html (viewing profiles), among others.
It doesn’t however seem to work when used in the template file overall_header.html
when browsing other types of pages.
For example, I would like the current user to see their rank whilst browsing any page on the forum - it would be great if there was a global template variable that would allow me to do this.
Does anyone know how this might be achieved?
Thanks,
Teeb
Re: Display user's rank on index with template variable
Posted: Mon Mar 11, 2019 12:30 pm
by mrgoldy
This will require some core modifications, especially in the
page_header()
function within
includes/functions.php
.
Around
this line add:
Code: Select all
$user_rank = phpbb_get_user_rank($user->data, ($user->data['user_id'] != ANONYMOUS ? $user->data['user_posts'] : false));
Then after
this line you could add:
Code: Select all
'CURRENT_USER_RANK_TITLE' => $user_rank['title'],
'CURRENT_USER_RANK_IMG' => $user_rank['img'],
You should now be able to use
{{ CURRENT_USER_RANK_TITLE }}
and
{{ CURRENT_USER_RANK_IMG }}
to display the current user's rank where ever you want in the template.
Re: Display user's rank on index with template variable
Posted: Mon Mar 11, 2019 12:34 pm
by teebling
mrgoldy wrote: ↑Mon Mar 11, 2019 12:30 pm
This will require some core modifications, especially in the
page_header()
function within
includes/functions.php
.
Around
this line add:
Code: Select all
$user_rank = phpbb_get_user_rank($user, ($user->data['user_id'] != ANONYMOUS ? $user->data['user_posts'] : false));
Then after
this line you could add:
Code: Select all
'CURRENT_USER_RANK_TITLE' => $user_rank['title'],
'CURRENT_USER_RANK_IMG' => $user_rank['img'],
You should now be able to use
{{ CURRENT_USER_RANK_TITLE }}
and
{{ CURRENT_USER_RANK_IMG }}
to display the current user's rank where ever you want in the template.
Receiving this error after the above edits:
Code: Select all
Fatal error: Uncaught Error: Cannot use object of type phpbb\user as array in /Applications/MAMP/htdocs/includes/functions_display.php:1524 Stack trace: #0 /Applications/MAMP/htdocs/includes/functions.php(4345): phpbb_get_user_rank(Object(phpbb\user), '423') #1 /Applications/MAMP/htdocs/index.php(251): page_header('A WoW Classic D...', true) #2 {main} thrown in /Applications/MAMP/htdocs/includes/functions_display.php on line 1524
Re: Display user's rank on index with template variable
Posted: Mon Mar 11, 2019 12:40 pm
by mrgoldy
Oh right, my bad.
Try this one:
Code: Select all
$user_rank = phpbb_get_user_rank($user->data, ($user->data['user_id'] != ANONYMOUS ? $user->data['user_posts'] : false));
Re: Display user's rank on index with template variable
Posted: Mon Mar 11, 2019 12:42 pm
by teebling
Tried it, can't log in now as I receive:
Code: Select all
Fatal error: Uncaught Error: Call to undefined function phpbb_get_user_rank() in /Applications/MAMP/htdocs/includes/functions.php:4347 Stack trace: #0 /Applications/MAMP/htdocs/includes/functions.php(2485): page_header('Login') #1 /Applications/MAMP/htdocs/ucp.php(84): login_box('index.php') #2 {main} thrown in /Applications/MAMP/htdocs/includes/functions.php on line 4347
EDIT:
Okay so apart from the logging in bug above ^ this is correctly showing the user's rank, cool!
However I am also using you NASR extension Posey - any way I can get it to show special ranks as well? Cheers.
Re: Display user's rank on index with template variable
Posted: Mon Mar 11, 2019 12:50 pm
by mrgoldy
Ah no, that's not the issue.
phpbb_get_user_rank()
is in
functions_display.php
, which I thought was included everywhere, unfortunately it is not.
So before the call to the
phpbb_get_user_rank
, add the following:
Code: Select all
if (!function_exists('phpbb_get_user_rank'))
{
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
}
But now you/we are treading on dangerous territory, as you're including a function file that is included in a lot of places, from a function that is literally called everywhere. The
!function_exists()
makes sure it's only included if it is not already. However, if the display functions are included elsewhere after the page header is called, without a check, there might still be double inclusions.
Re: Display user's rank on index with template variable
Posted: Mon Mar 11, 2019 12:51 pm
by mrgoldy
And about NASR, I did not finish that extension, Kasimi did.
I wouldn't honestly know anymore how to display them all everywhere.
Re: Display user's rank on index with template variable
Posted: Mon Mar 11, 2019 12:52 pm
by teebling
Understood.
So that has fixed the login issue, great.
Any way I can do this with your NASR extension {EXTRA_RANK_IMG} thing as well? That would be amazing.
Re: Display user's rank on index with template variable
Posted: Mon Mar 11, 2019 12:57 pm
by teebling
mrgoldy wrote: ↑Mon Mar 11, 2019 12:51 pm
And about NASR, I did not finish that extension, Kasimi did.
I wouldn't honestly know anymore how to display them all everywhere.
Okay cool, thanks so much for your help so far. I have just PMed Kasimi asking for help with NASR stuff.
Re: Display user's rank on index with template variable
Posted: Mon Mar 11, 2019 1:44 pm
by Mick
You should post in the extensions topic.