Register Members List Search Today's Posts Mark Forums Read

Reply
 
Article Options
Simplify your Template Conditionals
kall
Join Date: Apr 2004
Posts: 2,608

New Zealand
by kall kall is offline 06 Dec 2004

If you want to be able to show/hide things in your templates based on Usergroups, you can either use something like:


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

or


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

...but if those usergroup ids ever change, or you want to add more groups to the array, it could get time consuming, especially if you have multiple styles.

Wouldn't it be easier to be able to use:


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

?

Well now you can!

In includes/functions.php, find:

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

After, add

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

In adminfunctions_template.php find:


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

under, add:


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.


Save and upload includes/functions.php and adminfunctions_template.php and you are done.

You can now wrap
Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

around whatever you want to show to people in Usergroups 9, 10 or 11...and if you need to add usergroup 12 to the list, all you need to do is add it in the function.

Hoorah!

Last edited by kall; 06 Dec 2004 at 20:56..
Views: 4311
Reply With Quote
Comments
  #2  
Old 06 Dec 2004, 09:56
AN-net's Avatar
AN-net AN-net is offline
 
Join Date: Dec 2003
ooo nice
Reply With Quote
  #3  
Old 06 Dec 2004, 10:16
Revan's Avatar
Revan Revan is offline
 
Join Date: Jan 2004
Real name: Fillip
I feel confident when I say this won't work right away....I think
I only saw this when looking through vB files that there's some array of safe functions that the template parses, and it ignores everything else... I might be wrong, so dont shoot me!
Reply With Quote
  #4  
Old 06 Dec 2004, 10:27
Dean C's Avatar
Dean C Dean C is offline
 
Join Date: Jan 2002
Real name: Dean Clatworthy
Your thread title doesn't really simplify all template conditionals as it would imply. Something along the lines of 'Easy template conditional to select users from particular usergroups'. Thanks for releasing btw
__________________
Dean Clatworthy - Web Developer/Designer
Reply With Quote
  #5  
Old 06 Dec 2004, 10:43
Erwin's Avatar
Erwin Erwin is offline
 
Join Date: Jan 2002
Good idea, but you can simplify it even more by adding it as an Admin CP Options settings variable.

Because if you think changing a template is a pain when you want to add usergroups, at least you can do it anywhere. Changing a PHP file to add usergroups is much harder.

You're better off adding the group in your phpinclude_start template -

e.g.

$specialgroupid = "1,2,3,4,5";

Then using that anywhere in your templates:

<if condition="in_array($bbuserinfo[usergroupid], array($specialgroupid))">

Then just change the numbers in your phpinclude_start template anytime.
Reply With Quote
  #6  
Old 06 Dec 2004, 20:59
kall's Avatar
kall kall is offline
 
Join Date: Apr 2004
Real name: Ace
Originally Posted by Revan
I feel confident when I say this won't work right away....I think
I only saw this when looking through vB files that there's some array of safe functions that the template parses, and it ignores everything else... I might be wrong, so dont shoot me!
Oopsie. You're right...I realised this as I was falling asleep last night. adminfunctions_template.php needs an edit too.

Sorted.

@Dean: I know...I'm crap at descriptive titles that don't run the length of 2 pages. 'Add new Usergroup Macros for Template Conditionals' was one I played with. Feel free to edit the title to something a bit better.
__________________
vBulletin Styles (All styles compatible with 3.8.4 - Steel Blue 4.0 Available) | vBulletin Hosting
Reply With Quote
  #7  
Old 06 Dec 2004, 22:18
Koutaru's Avatar
Koutaru Koutaru is offline
 
Join Date: Feb 2003
Real name: Julie
Really nice! I was wondering how to do this a while back!
/me installs
__________________
http://www.miyechi.com/storage/sig.png
Miyechi - Adventure inside
Reply With Quote
  #8  
Old 19 Jan 2005, 13:49
neocorteqz's Avatar
neocorteqz neocorteqz is offline
 
Join Date: May 2002
Real name: George E Collins Jr
this thread was of some use. Thanks.
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Article Options

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


New To Site? Need Help?

All times are GMT. The time now is 22:06.

Layout Options | Width: Wide Color: