RE: [SMARTY] Question about sessions
| From: | Rod Kreisler | Date: | Wed, 24 Jul 2002 20:16:15 +0000 |
| Subject: | RE: [SMARTY] Question about sessions | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-5426@lists.php.net to get a copy of this message | ||
Right on, Monte!
Far too much of this stuff coming across the list lately. It's like
everybody wants to remove all the logic from the app and put it in the
template. BAH!
Just my 1.34 cents (after inflation).
Rod
-----Original Message-----
From: Monte Ohrt [mailto:monte@ispi.net]
Sent: Wednesday, July 24, 2002 4:04 PM
To: Jan Rosier
Cc: smarty-general@lists.php.net
Subject: Re: [SMARTY] Question about sessions
Maybe someone will get something from this, so I'll mention it :-) I
once had nasty {if} conditions in my templates and quickly learned
something. Ideally, this shouldn't be the job of the template. The
template doesn't care about sessions, it shouldn't be bothered with
isset(), etc.
So the ideal solution, assign a template var.
{if $user_is_admin}
...
{/if}
Now how did "user_is_admin" get set? was it session info, a db call,
something else? It doesn't matter. All the template wants to know is, is
this user an admin or not? Leave the details to the application.
Also to the template designer, this:
{if $user_is_admin}
...
{/if}
Makes a _lot_ more sense than this:
{if isset($smarty.session.user) AND $smarty.session.user eq 'admin'}
...
{/if}
I once had something to this order in a template:
{if $price eq 0 or ($end_date ne "" and $end_date lt
$smarty.now|date_format:"%Y/%m/%d 00:00:00")}
...
{/if}
and reduced it to this:
{if $display_as_free}
...
{/if}
keeping template logic short and easy made a huge difference in
understandability and template/code maintainability.
Monte
Jan Rosier wrote:
> Maybe this is something for you (I didn't test it ;-) )
>
> {if isset($smarty.session.user) AND $smarty.session.user eq 'admin'}
> ....
> {/if}
>
> Greetings
> Jan Rosier
>
> ----- Original Message -----
> From: "Garland foster" <garland_foster@salutia.com>
> To: <smarty-general@lists.php.net>
> Sent: Wednesday, July 24, 2002 8:15 PM
> Subject: [SMARTY] Question about sessions
>
>
> Hi all,
>
> I want to know the best solution to check if a session variable is set, if
I
> use
> {if $smarty.session.user eq 'admin'}
> Code for admin
> {else}
> Code for normal users
> {/if}
>
> Then I have a problem if error_reporting is set to all because the index
> user cannot be found
> in the compiled template.
>
> Ideas?
>
> Thanks,
> Garland.
>
>
>
>
>
--
Monte Ohrt <monte@ispi.net>
Director of Technology, ispi Inc.
--
Smarty General Mailing List (http://smarty.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php