Welcome Guest, Not a member yet? Register   Sign In
if, else if and else statements
#1

[eluser]mattoebs[/eluser]
Hi everyone,

I'm trying to write some code that will show one content set to an admin, another to a user and redirect anyone else to a log in page.

at the moment i have

{if $userdata.admin == 'true'}
$content
{if $userdata.manager == 'true'}
$man_content
{else}
redirect (admin/login)
{/if}

It's not working though it keeps telling me the else statement is creating an error. Can anyone help?
#2

[eluser]Dam1an[/eluser]
I'm not to sure about what it is using templates, but in raw PHP, its
Code:
if($admin) {
  // display admin content
} else if ($manager) {
  // display manager content
} else {
  redirect('admin/login');
}
#3

[eluser]jdfwarrior[/eluser]
Even if your using templates you can still use regular php in the template view. Use:

Code:
<? if ($this == "that"): ?>
html code here
<? else: ?>
more code
<? endif; ?>
#4

[eluser]mattoebs[/eluser]
I am using the smarty classes in my templates and it doesn't seem to pick up on the PHP tags
#5

[eluser]Jagar[/eluser]
Try the following:

Code:
{if $userdata.admin}
$content
{if $userdata.manager}
$man_content
{else}
redirect (admin/login)
{/if}

or

Code:
{if $userdata.admin == true}
$content
{if $userdata.manager == true}
$man_content
{else}
redirect (admin/login)
{/if}

or
Code:
{if $userdata.admin == "true"}
$content
{if $userdata.manager == "true"}
$man_content
{else}
redirect (admin/login)
{/if}

also check to see if there's anything in $userdata.admin by doing
Code:
<h1>{$userdata.admin}</h1>
#6

[eluser]mattoebs[/eluser]
thanks jaguar that worked Smile




Theme © iAndrew 2016 - Forum software by © MyBB