phpBB Snippets<!-- IF STATEMENTS -->

Post Reply
User avatar
Topic Starter
Restless Rancor
Great Britain

Site Admin
New Member
Posts: 48
Joined: October 15th, 2018, 3:14 pm
Age: 25
Location: Hampshire, England



Post by Restless Rancor » October 16th, 2018, 7:16 am

There are many IF statements you can use in your template files. This topic outlines some of the basics as well as some I come across that could be useful. You can find a full list of default Global Template Variables for phpBB here.

Note: The first part of this post has been copied and pasted around many different forums over the years. As such, I have been unable to find the original author for credit.

<!-- IF S_USER_LOGGED_IN --> If a user is logged in this will display.
<!-- IF S_REGISTERED_USER --> If user is logged in and not a bot this will display.
<!-- IF S_IS_BOT --> If a bot this will display.
<!-- IF S_DISPLAY_SEARCH --> If displays search this will display.
<!-- IF S_DISPLAY_PM --> If display a PM this will display.
<!-- IF U_MCP --> If Moderator this will display.
<!-- IF U_ACP --> If Administrator this will display.
<!-- IF FORUM_ID --> Displays the code between if particular forum. AND, this will display.
<!-- IF SCRIPT_NAME == "viewtopic" --> Some content. AND, this will display.
<!-- IF S_USERNAME eq "TheGeneral" --> You get the picture yet? .. but in this case, only for me!!
<!-- IF FORUM_ID eq 2 --> Welcome to Forum Number 2, this only displays in Forum Number 2. DUH!
<!-- IF FORUM_ID eq 2 and S_REGISTERED_USER --> Welcome to Forum ID #2. Yes, you are a registered user.

Also, you can use the following operands
or / ||
and / &&
eq / ==
You can use either the language ones (or, and, eq) or the other ones (||, &&, ==).
php Operators list

OMG, What 'else' is there:
<!-- IF SCRIPT_NAME == "viewtopic" --> This will show... <!-- ELSE --> Otherwise, this will show if not viewing a topic.

Technical Example:

Code: Select all

<title><!-- IF UNREAD_NOTIFICATIONS_COUNT -->({UNREAD_NOTIFICATIONS_COUNT}) <!-- ENDIF --><!-- IF S_IN_MCP -->{L_MCP} &bull; <!-- ELSEIF S_IN_UCP -->{L_UCP} &bull; <!-- ENDIF --><!-- IF SCRIPT_NAME eq 'index' -->{SITENAME} &bull; {SITE_DESCRIPTION}<!-- ELSE -->{PAGE_TITLE} <!-- IF SCRIPT_NAME == "viewtopic" -->| {FORUM_NAME} <!-- ENDIF -->| {SITENAME}<!-- ENDIF --></title>
Disable in specific style:

Code: Select all

{% if|lower != 'mystyle' %}
    this is not displayed in MyStyle
{% endif %}

These aren't the droids you're looking for.

Post Reply

Topic Subscribers

1 user subscribed to this topic: Restless Rancor