Help with Smarty please

Soldato
Joined
2 May 2004
Posts
19,950
Hi,

I've decided I want to start using a template system for all my scripts, so I've been looking at Smarty.

Am I right in saying that my layout (e.g. divs, tables, etc.) will be in the tpl file, and all the rest (error reporting etc.) in the PHP file?

The main bit I'm stuck on is showing a different layout according to a database query e.g.

Code:
if($user = isadmin)
{
  <table>
    This is a table for the administrator
  </table>
}
else
{
  <table>
    This is a table for a normal user
  </table>
}

Would I use the built in Smarty if and else to do that? Or is there something I'm missing?

Thanks,
Craig.
 
Neater to setup a variable called $isadmin and set it to true then pass it to Smarty, making your template code:

Code:
{if $isadmin}
  <table>
    This is a table for the administrator
  </table>
{else}
  <table>
    This is a table for a normal user
  </table>
{/if}

But also possible to do it with just the one variable, via {if $user eq "isadmin"} :)

:)
 
Beansprout said:
Neater to setup a variable called $isadmin and set it to true then pass it to Smarty, making your template code:

Code:
{if $isadmin}
  <table>
    This is a table for the administrator
  </table>
{else}
  <table>
    This is a table for a normal user
  </table>
{/if}

But also possible to do it with just the one variable, via {if $user eq "isadmin"} :)

:)

I'll set up a variable for it, thanks :)

So I guess using if/else in the template file is the way to do this then?

Thanks,
Craig.
 
Back
Top Bottom