[solved] If statement within template HTML

Get help with installation and running phpBB 3.0.x here. Please do not post bug reports, feature requests, or MOD-related questions here.
Scam Warning
Forum rules
END OF SUPPORT: 1 January 2017 (announcement)
Locked
nigelt74
Registered User
Posts: 31
Joined: Mon Jul 11, 2005 6:26 am

[solved] If statement within template HTML

Post by nigelt74 »

Hi all

The situation is this i have added pages in to the forum to allow me to integrate a chat program, I have followed the instructions from the wiki here, and it has been working beautifully since the launch of phpBB3.

However I now need to display a message for one specific user, and I cannot workout how to do this

If on the previously mentioned page you go to the create your template page section it has what appears to be an IF statement, so I have tried using an if statement (within a comment obviously)

But nothing i do works

I have assigned the users name to a variable called {chatter} and it works and displays within the template perfectly

In the wiki the statement uses an 'is' rather than '==' but everytime I tried using an 'is' I got syntax errors

Code: Select all

<!-- IF chatter == nigel -->Nigel remember to feed the hedgehog<!-- ELSE -->feed the dragon<!-- ENDIF -->

But no matter what I do I only get the ELSE "feed the dragon" displayed

I have tried

IF chatter == 'nigel'
IF {chatter} == 'nigel'
IF chatter == "nigel"
IF {chatter} == "nigel"
IF chatter is 'nigel'
IF {chatter} is 'nigel'
IF chatter is "nigel"
IF {chatter} is "nigel"
IF ({chatter} is 'nigel')

all the 'is' gave errors about missing '{' or '('

any help would be greatly appreciated
Last edited by nigelt74 on Mon Sep 08, 2008 11:10 pm, edited 1 time in total.
User avatar
Erik Frèrejean
Former Team Member
Posts: 9899
Joined: Tue Oct 09, 2007 9:09 am
Location: The Netherlands, 3.0.x Support Forum
Name: Erik Frèrejean
Contact:

Re: If statement within template HTML

Post by Erik Frèrejean »

It should be "==", "is" can only be used in a comparison statement (for example the check:

Code: Select all

<!-- IF row.S_ROW_COUNT is even -->
[/i]
Support Toolkit | Support Request Template | Knowledge Base | phpBB 3.0.x documentation
I don't give support via PM or IM! (all unsolicited pms will be trashed!)
nigelt74
Registered User
Posts: 31
Joined: Mon Jul 11, 2005 6:26 am

Re: If statement within template HTML

Post by nigelt74 »

Thanks Erik that makes more sense

But I still can't get the if statement to work,

What language is it in as I kept getting syntax errors
User avatar
Galaxy21
Registered User
Posts: 111
Joined: Mon Aug 13, 2007 12:03 am
Location: Dresden, Deutschland
Contact:

Re: If statement within template HTML

Post by Galaxy21 »

How is "chatter" filled on the PHP side?
User avatar
Erik Frèrejean
Former Team Member
Posts: 9899
Joined: Tue Oct 09, 2007 9:09 am
Location: The Netherlands, 3.0.x Support Forum
Name: Erik Frèrejean
Contact:

Re: If statement within template HTML

Post by Erik Frèrejean »

nigelt74 wrote:Thanks Erik that makes more sense

But I still can't get the if statement to work,

What language is it in as I kept getting syntax errors
Can you post the errors? Without them it is really hard to find the problem ;).
Support Toolkit | Support Request Template | Knowledge Base | phpBB 3.0.x documentation
I don't give support via PM or IM! (all unsolicited pms will be trashed!)
nigelt74
Registered User
Posts: 31
Joined: Mon Jul 11, 2005 6:26 am

Re: If statement within template HTML

Post by nigelt74 »

Hi Erik the errors only happen if I use "is" rather than "=="

It always goes to the else condition

Code: Select all

    
<!-- IF chatter == nigel -->Nigel remember to feed the hedgehog<!-- ELSE -->feed the dragon<!-- ENDIF -->

Hi {chatter}

if the chatter is david it will give me
Feed the Dragon

Hi David
If the chatter is nigel it gives me
Feed the dragon

Hi nigel
Which is not what I am after

Galaxy21

Code: Select all

// Gets the username
$chatter = $user->data['username'];

// redirect User to login page
if ($chatter == "Anonymous")
    {
        header("Location: http://mysite.com/forum/ucp.php?mode=login");
    }
/**/
// specify styles and/or localisation
// in this example, we specify that we will be using the file: my_language_file.php
$user->setup('mods/chat-index');

/*
* All of your coding will be here, setting up vars, database selects, inserts, etc...
*
* This is a very primitive example, it’s meant to show you a working example only.
*/

// A typical usage for sending your variables to your template.
$template->assign_vars(array(
	  'chatter' => $chatter,
));
It works, the username displays correctly however it's just the IF statement that isn't working
User avatar
Erik Frèrejean
Former Team Member
Posts: 9899
Joined: Tue Oct 09, 2007 9:09 am
Location: The Netherlands, 3.0.x Support Forum
Name: Erik Frèrejean
Contact:

Re: If statement within template HTML

Post by Erik Frèrejean »

I can't test it right now, but I have used something like this:

Code: Select all

<!-- IF S_PAGE == 'list_polls' -->
	[some HTML]
<!-- ELSEIF S_PAGE == 'reveal_poll' -->
	[some HTML]
<!-- ENDIF -->
And that works without a problem the only difference are the single quotes. You might want to try it with those thus:

Code: Select all

<!-- IF chatter == 'nigel' -->
Something you should do nevertheless cause nigel is a String.
Support Toolkit | Support Request Template | Knowledge Base | phpBB 3.0.x documentation
I don't give support via PM or IM! (all unsolicited pms will be trashed!)
User avatar
Brf
Support Team Member
Support Team Member
Posts: 52142
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}
Contact:

Re: If statement within template HTML

Post by Brf »

Why arent you using S_USERNAME ?
Then you could just:

Code: Select all

<!-- IF S_USERNAME == "nigel" -->
Also, note that all template variables should be in UPPERCASE.
User avatar
Galaxy21
Registered User
Posts: 111
Joined: Mon Aug 13, 2007 12:03 am
Location: Dresden, Deutschland
Contact:

Re: If statement within template HTML

Post by Galaxy21 »

Brf wrote:Also, note that all template variables should be in UPPERCASE.
Then...

Code: Select all

<!-- IF CHATTER == "nigel" -->
... might do the trick ;)
nigelt74
Registered User
Posts: 31
Joined: Mon Jul 11, 2005 6:26 am

Re: If statement within template HTML

Post by nigelt74 »

Thanks all, It works perfectly

Code: Select all

<!-- IF S_USERNAME == 'nigel' -->
   <font color="#FF0000">Hello Nigel, Feed the hedgehog</font><br>
<!-- ELSEIF S_USERNAME != 'nigel' -->
<br>Hi {chatter} <br>  <br>
<!-- ENDIF -->
Yes I could probably replace chatter with S_USERNAME but then I would forget how to pass variables

Thanks again
User avatar
Erik Frèrejean
Former Team Member
Posts: 9899
Joined: Tue Oct 09, 2007 9:09 am
Location: The Netherlands, 3.0.x Support Forum
Name: Erik Frèrejean
Contact:

Re: [solved] If statement within template HTML

Post by Erik Frèrejean »

You don't need the elseif ;).

Code: Select all

<!-- IF S_USERNAME == 'nigel' -->
   <font color="#FF0000">Hello Nigel, Feed the hedgehog</font><br>
<!-- ELSE -->
<br>Hi {chatter} <br>  <br>
<!-- ENDIF -->
Support Toolkit | Support Request Template | Knowledge Base | phpBB 3.0.x documentation
I don't give support via PM or IM! (all unsolicited pms will be trashed!)
Locked

Return to “[3.0.x] Support Forum”