Page 1 of 1

[solved] If statement within template HTML

Posted: Tue Sep 02, 2008 9:14 pm
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

Re: If statement within template HTML

Posted: Wed Sep 03, 2008 10:59 am
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]

Re: If statement within template HTML

Posted: Thu Sep 04, 2008 9:57 am
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

Re: If statement within template HTML

Posted: Thu Sep 04, 2008 10:00 am
by Galaxy21
How is "chatter" filled on the PHP side?

Re: If statement within template HTML

Posted: Thu Sep 04, 2008 10:24 am
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 ;).

Re: If statement within template HTML

Posted: Thu Sep 04, 2008 8:31 pm
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

Re: If statement within template HTML

Posted: Thu Sep 04, 2008 8:52 pm
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.

Re: If statement within template HTML

Posted: Thu Sep 04, 2008 8:54 pm
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.

Re: If statement within template HTML

Posted: Fri Sep 05, 2008 9:35 am
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 ;)

Re: If statement within template HTML

Posted: Mon Sep 08, 2008 11:10 pm
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

Re: [solved] If statement within template HTML

Posted: Tue Sep 09, 2008 9:37 am
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 -->