To display something for some user

For support and discussion related to templates, themes, and imagesets in phpBB 3.2.
Post Reply
bzozoo
Registered User
Posts: 24
Joined: Mon Feb 11, 2019 6:33 am

To display something for some user

Post by bzozoo » Sun Feb 24, 2019 11:19 pm

Hi!

I use this code in template

Code: Select all

	<!-- IF S_USERNAME eq 'User' -->
	<center>TEXT</center>
	  <!-- ENDIF --> 
It's OK It's work. It is display the text for User named user
But I want to define more user with one code.
I want that User1 User2 , User3....UserN or UserABC, UserDEFG... etc can to see this text, but that user can not see who name is not start with "User"

I know this is an easy code, but I not found it.

Thanks for help
(Sorry my poor English language)

User avatar
thecoalman
Community Team Member
Community Team Member
Posts: 3352
Joined: Wed Dec 22, 2004 3:52 am
Location: Pennsylvania, U.S.A.
Contact:

Re: To display something for some user

Post by thecoalman » Mon Feb 25, 2019 1:33 am

I'm not quite sure I understand what you are asking but if you are familiar with php you can create your own template variables. in includes/functions.php around line 4345 you will find:

Code: Select all

	// The following assigns all _common_ variables that may be used at any point in a template.
	$template->assign_vars(array(
		'SITENAME'					=> $config['sitename'],
		'SITE_DESCRIPTION'				=> $config['site_desc'],

Code: Select all

	// The following assigns all _common_ variables that may be used at any point in a template.
	$template->assign_vars(array(
		'MY_CUSTOM_TEMPLATE_VAR'			=> (substr($user->data['username'], 0, 4) == 'USER')  ? 'Some text' : false,
		'SITENAME'					=> $config['sitename'],
		'SITE_DESCRIPTION'				=> $config['site_desc'],
In the template:

Code: Select all

<!-- IF MY_CUSTOM_TEMPLATE_VAR -->
	<center>{MY_CUSTOM_TEMPLATE_VAR}</center>
<!-- ENDIF --> 

Untested but should work.

http://php.net/manual/en/function.substr.php
“Results! Why, man, I have gotten a lot of results! I have found several thousand things that won’t work.”

Attributed - Thomas Edison

User avatar
Lumpy Burgertushie
Registered User
Posts: 66849
Joined: Mon May 02, 2005 3:11 am
Contact:

Re: To display something for some user

Post by Lumpy Burgertushie » Mon Feb 25, 2019 3:28 am

I think it would go something like this:

Code: Select all

	<!-- IF S_USERNAME eq 'User' or 'user2' or 'user3' -->
	<span style="text-align: center;"> your text here </span>
	  <!-- ENDIF --> 
I'm baaaaaccckkkk. still doing work on donation basis. PM your needs.

Premium phpBB 3.2 Styles by PlanetStyles.net

If a tree falls in the forest and nobody is there, does it make a sound?

bzozoo
Registered User
Posts: 24
Joined: Mon Feb 11, 2019 6:33 am

Re: To display something for some user

Post by bzozoo » Mon Feb 25, 2019 4:25 pm

Hi Lumpy Burgertushie

Yes , I want similar, but this code not good for me, becous I have more UserXYZ or User123456 named user, and I need to edit this code their names with manual if I want to add new user named user. I want an automatic system.

bzozoo
Registered User
Posts: 24
Joined: Mon Feb 11, 2019 6:33 am

Re: To display something for some user

Post by bzozoo » Mon Feb 25, 2019 4:34 pm

Hi thecoalman

I don't know what your code is doing, and this code how can solve my problem.
This code shows for all User named user a text? Example Can "User2815" and "UserXXXXXXX" and etc see what I write after "IF MY_CUSTOM_TEMPLATE_VAR"?

User avatar
thecoalman
Community Team Member
Community Team Member
Posts: 3352
Joined: Wed Dec 22, 2004 3:52 am
Location: Pennsylvania, U.S.A.
Contact:

Re: To display something for some user

Post by thecoalman » Mon Feb 25, 2019 4:46 pm

Code: Select all

'MY_CUSTOM_TEMPLATE_VAR'			=> (substr($user->data['username'], 0, 4) == 'USER')  ? 'Some text' : false,
This tests to see if the first four characters are "USER". If true the template variable holds "Some text", if not it evaluates to false. When using the IF clause in a template if the variable is false it is skipped.


Code: Select all

'MY_CUSTOM_TEMPLATE_VAR'			=> (substr($user->data['username'], 0, 5) == 'OTHER')  ? 'Some text' : false,
That would test to see if the first five characters are "OTHER". Note it will be case sensitive.


You can also do this:

Code: Select all

'MY_CUSTOM_TEMPLATE_VAR'			=> (substr($user->data['username'], 0, 5) == 'OTHER')  ? true : false,

Code: Select all

<!-- IF MY_CUSTOM_TEMPLATE_VAR -->
	Anything you want. 
<!-- ENDIF --> 
“Results! Why, man, I have gotten a lot of results! I have found several thousand things that won’t work.”

Attributed - Thomas Edison

User avatar
thecoalman
Community Team Member
Community Team Member
Posts: 3352
Joined: Wed Dec 22, 2004 3:52 am
Location: Pennsylvania, U.S.A.
Contact:

Re: To display something for some user

Post by thecoalman » Mon Feb 25, 2019 4:56 pm

There was mistake in my original post, I forgot the {brackets} for the template variable.

Code: Select all

<!-- IF MY_CUSTOM_TEMPLATE_VAR -->
	<center>{MY_CUSTOM_TEMPLATE_VAR}</center>
<!-- ENDIF --> 
Edit: Just to add you should not use <center>, Lumpy provided example on one way to do it.
“Results! Why, man, I have gotten a lot of results! I have found several thousand things that won’t work.”

Attributed - Thomas Edison

bzozoo
Registered User
Posts: 24
Joined: Mon Feb 11, 2019 6:33 am

Re: To display something for some user

Post by bzozoo » Mon Feb 25, 2019 5:24 pm

Thanks! I understand it now!

I modificated your code and now It work. It is good for me! :)

My Username is "FeelGood" in my forum

I added this code to includes/functions.php

Code: Select all

'MY_CUSTOM_TEMPLATE_VAR'		=> (substr($user->data['username'], 0, 4) == 'Feel')  ? true : false,
And this code to template html:

Code: Select all

<center>
<!-- IF MY_CUSTOM_TEMPLATE_VAR -->
	Hi FeeelGood 
	
	<!-- ELSE -->
	You are NOT FeelGood
<!-- ENDIF --> 
</center>
Thanks your solution! :)

But I have a new question now :)
If I dont know how many characters are before name of user? How can I solute this example in this similar situaton?
Example I have a "MoreFeelGood" and "MoreMoreFeelGood" and "MoreFeelGood15" named user in my forum. I want that they see "Hi FeelGood" text too.
But I dont know how many caracher are before FeelGood.

The point would be to have "FEELGOOD" anywhere on their name, they would get "HI FEELGOOD"

Thanks in advance for your help!

User avatar
thecoalman
Community Team Member
Community Team Member
Posts: 3352
Joined: Wed Dec 22, 2004 3:52 am
Location: Pennsylvania, U.S.A.
Contact:

Re: To display something for some user

Post by thecoalman » Mon Feb 25, 2019 9:28 pm

“Results! Why, man, I have gotten a lot of results! I have found several thousand things that won’t work.”

Attributed - Thomas Edison

bzozoo
Registered User
Posts: 24
Joined: Mon Feb 11, 2019 6:33 am

Re: To display something for some user

Post by bzozoo » Mon Feb 25, 2019 10:53 pm

Hi!

It will be work?

Code: Select all

'MY_CUSTOM_TEMPLATE_VAR'		=> (strpos($user->data['username']) == 'Feel')  ? true : false,
I can not try it now, becouse I write from Phone.

User avatar
thecoalman
Community Team Member
Community Team Member
Posts: 3352
Joined: Wed Dec 22, 2004 3:52 am
Location: Pennsylvania, U.S.A.
Contact:

Re: To display something for some user

Post by thecoalman » Mon Feb 25, 2019 11:49 pm

No that will not work, see if the documentation on php is in your language.

Code: Select all

'MY_CUSTOM_TEMPLATE_VAR'		=> strpos($user->data['username'], 'Feel') ,
“Results! Why, man, I have gotten a lot of results! I have found several thousand things that won’t work.”

Attributed - Thomas Edison

bzozoo
Registered User
Posts: 24
Joined: Mon Feb 11, 2019 6:33 am

Re: To display something for some user

Post by bzozoo » Tue Feb 26, 2019 9:36 pm

Thanks your all helps! Now it work! ;)

Post Reply

Return to “[3.2.x] Styles Support & Discussion”