If Statements

Support for mods released by phpbbmodders.net found at either https://github.com/phpbbmodders/ or the MODDB at http://www.phpbb.com
Forum rules
Please only request support for mods released by phpbbmodders.net found at either https://github.com/phpbbmodders/ or the MODDB at http://www.phpbb.com
User avatar
Ooopsie
Supporter
Supporter
Posts: 1213
Joined: 19 Aug 2010, 16:34
Location: Index, WA
Contact:

If Statements

Post by Ooopsie »

Thought I'd post this for everybody. Quite useful and it has helped me quite a bit.

Original Author: RMcGirr83

<!-- IF S_USER_LOGGED_IN --> If a user is logged in
<!-- IF S_USER_LOGGED_IN -->your content here (for users logged in)<!-- ELSE -->your content here (for viewing as a guest)<!-- ENDIF -->
<!-- IF S_REGISTERED_USER --> If user is logged in and not a bot
<!-- IF S_AUTOLOGIN_ENABLED --> If auto login is allowed
<!-- IF S_BOARD_DISABLED --> If board is disabled
<!-- IF S_IS_BOT --> If a bot
<!-- IF S_USER_PM_POPUP --> If pop up pm is on
<!-- IF S_DISPLAY_SEARCH --> If displays search
<!-- IF S_DISPLAY_PM --> If display a PM
<!-- IF S_DISPLAY_MEMBERLIST --> If display memberlist.php
<!-- IF U_MCP --> If Moderator
<!-- IF U_ACP --> If Administrator
<!-- IF S_IS_LINK --> If its a link
<!-- IF S_UNREAD_FORUM --> If forum is unread
<!-- IF S_READ_FORUM --> If forum is read
<!-- IF S_LOCKED_FORUM --> If forum is locked
<!-- IF S_LIST_SUBFORUMS --> If there is a list of subforums
<!-- IF S_SUBFORUMS --> If a subforum
<!-- IF S_IS_CAT --> If a category
<!-- IF S_IS_POST --> If a post
<!-- IF FORUM_ID --> Displays the code between the switches if the user is viewing a particular forum.
<!-- IF SCRIPT_NAME == "index" -->some content<!-- ENDIF --> (Others you can use, viewtopic,viewforum,memberlst,faq etc)
<!-- IF S_USERNAME eq "Stoker" -->Some content here<!-- ENDIF -->

Examples
Let's say you wanted something to show in an html file for registered users only, then you could use the following

Code: Select all

    <!-- IF S_REGISTERED_USER -->Hello, welcome to blahblah.com<!-- ENDIF -->


Which will only show to registered users.
or

Code: Select all

    <!-- IF FORUM_ID eq 2 -->Welcome to Forum Number 2<!-- ENDIF -->


Which will only show if the viewer is within Forum Id #2.

You can also combine the IF's

Code: Select all

    <!-- IF FORUM_ID eq 2 and S_REGISTERED_USER -->Welcome to Forum ID #2 and you are a registered user<!-- ENDIF -->


Also, you can use the following operands as well

or ( || )
and ( && )
eq ( == )

You can use either the language ones (or, and, eq) or the other ones ( ||, &&, ==).

Remember each time you have a <!-- IF something --> statement you must also have an ending <!-- ENDIF --> statement, else you will get errors when the templating engine does it's stuff.
mikef35
New member
New member
Posts: 38
Joined: 21 Feb 2012, 21:05

Re: If Statements

Post by mikef35 »

Thanks, very helpful. I will reference this a lot!
jabhi
Member
Member
Posts: 77
Joined: 14 Mar 2012, 06:34

Re: If Statements

Post by jabhi »

Thanks for share ....
Go phpBB go... Respected : Developers, Supporters.
User avatar
Stoker
Member
Member
Posts: 198
Joined: 14 May 2011, 20:54
Contact:

Re: If Statements

Post by Stoker »

Ooopsie wrote:<!-- IF S_USERNAME eq "Stoker" -->Some content here<!-- ENDIF -->

Should be: <!-- IF S_USERNAME eq 'Stoker' -->Some content here<!-- ENDIF -->
steve
Master of posting
Master of posting
Posts: 1213
Joined: 12 Jul 2009, 19:14
Location: uk
Contact:

Re: If Statements

Post by steve »

\"" Why? "\"
Steve ©
User avatar
Stoker
Member
Member
Posts: 198
Joined: 14 May 2011, 20:54
Contact:

Re: If Statements

Post by Stoker »

My mistake, first example works fine.
steve
Master of posting
Master of posting
Posts: 1213
Joined: 12 Jul 2009, 19:14
Location: uk
Contact:

Re: If Statements

Post by steve »

Here's How to get your real script path ,phpbb must of defined SCRIPT_PATH for there if statements
only for root files ./ not ./../files contained in a folder for example.
So if you want to hilite what page you are on in a menu for example
after your $template->assign_vars(array(
of your php file add:

Code: Select all

            'MOD_SCRIPT_PATH'      => (isset($_SERVER['SCRIPT_NAME'])) ? $_SERVER['SCRIPT_NAME'] : '',


And in your html use:

Code: Select all

<!-- IF MOD_SCRIPT_PATH -->class="active"<!-- else --->class="not_active"<!-- endif -->


See the script path detected here http://www.phpbb3-showroom.org/script/test.php
Steve ©
User avatar
Stoker
Member
Member
Posts: 198
Joined: 14 May 2011, 20:54
Contact:

Re: If Statements

Post by Stoker »

steve© wrote:Here's How to get your real script path ,phpbb must of defined SCRIPT_PATH for there if statements
only for root files ./ not ./../files contained in a folder for example.
So if you want to hilite what page you are on in a menu for example
after your $template->assign_vars(array(
of your php file add:

Code: Select all

            'MOD_SCRIPT_PATH'      => (isset($_SERVER['SCRIPT_NAME'])) ? $_SERVER['SCRIPT_NAME'] : '',


And in your html use:

Code: Select all

<!-- IF MOD_SCRIPT_PATH -->class="active"<!-- else --->class="not_active"<!-- endif -->


See the script path detected here http://www.phpbb3-showroom.org/script/test.php

I've done it almost same way:
'S_IN_PORTAL' => true,
and
<!-- IF S_IN_PORTAL -->
juango
New member
New member
Posts: 9
Joined: 03 Jul 2012, 02:27

Re: If Statements

Post by juango »

the way Stoker does it is the way i have been doing it for a while now, most mods use them this way.
User avatar
Sniper_E
MOD Team
MOD Team
Posts: 591
Joined: 13 Jun 2011, 16:53
Location: Shreveport, LA
Contact:

Re: If Statements

Post by Sniper_E »

Yep, I've always done it Stoker's way too.
No is NEVER an Option and NEVER is the only Option when it comes to Giving Up!
Daniel
New member
New member
Posts: 3
Joined: 05 Jun 2011, 08:05

Re: If Statements

Post by Daniel »

steve© wrote:Here's How to get your real script path ,phpbb must of defined SCRIPT_PATH for there if statements
only for root files ./ not ./../files contained in a folder for example.
So if you want to hilite what page you are on in a menu for example
after your $template->assign_vars(array(
of your php file add:

Code: Select all

            'MOD_SCRIPT_PATH'      => (isset($_SERVER['SCRIPT_NAME'])) ? $_SERVER['SCRIPT_NAME'] : '',


And in your html use:

Code: Select all

<!-- IF MOD_SCRIPT_PATH -->class="active"<!-- else --->class="not_active"<!-- endif -->


See the script path detected here http://www.phpbb3-showroom.org/script/test.php



I got told that I shouldn't use the $_SERVER varable as it not safe and can't be truested. What the deal with that?
steve
Master of posting
Master of posting
Posts: 1213
Joined: 12 Jul 2009, 19:14
Location: uk
Contact:

Re: If Statements

Post by steve »

Not come across that statement pressume phpbb.com uses superglobals or rewrites them blah blah ,my code snippet is fine as it is checked that the $var exist's.
Who said that its not safe or can't be trusted?
Steve ©
User avatar
RMcGirr83
Supporter
Supporter
Posts: 6242
Joined: 30 Nov 2006, 14:23
Real name: Rich McGirr

Re: If Statements

Post by RMcGirr83 »

juango wrote:the way Stoker does it is the way i have been doing it for a while now, most mods use them this way.


But that will always return true, whereas what Steve has posted is different in that it checks for what file the user is on (index.php, etc).
User avatar
Sniper_E
MOD Team
MOD Team
Posts: 591
Joined: 13 Jun 2011, 16:53
Location: Shreveport, LA
Contact:

Re: If Statements

Post by Sniper_E »

When setting up individual links in your header, the <!-- IF S_IN_PORTAL --> type works fine.

Steve's codes would definitely be needed if you had your navigation links setup in an array.
Example: At STG, David has the nav links in an array.

In the prosilver header he has all the links setup like this...

Code: Select all

            <!-- BEGIN header_nav -->
            <li class="icon-mods"><a class="nav" href="{header_nav.U_URL}">{header_nav.LANG}</a></li>
            <!-- END header_nav -->

If he wanted the selected link to be highlighted, it would have to be coded like this...

Code: Select all

            <!-- BEGIN header_nav -->
            <li class="icon-mods<!-- IF MOD_SCRIPT_PATH --> active<!-- endif -->"><a class="nav" href="{header_nav.U_URL}">{header_nav.LANG}</a></li>
            <!-- END header_nav -->
I personally wouldn't use the not_active class if it wasn't selected.

Thanks Steve! I'm saving this bit of codes for future use. :rock:
No is NEVER an Option and NEVER is the only Option when it comes to Giving Up!
juango
New member
New member
Posts: 9
Joined: 03 Jul 2012, 02:27

Re: If Statements

Post by juango »

correct Rich, that is what i meant to say that it's used for mods, and it's added depending on the page you are on
Post Reply