Re: [SMARTY] Question about sessions
| From: | Ben Godfrey | Date: | Wed, 24 Jul 2002 20:22:15 +0000 |
| Subject: | Re: [SMARTY] Question about sessions | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-5428@lists.php.net to get a copy of this message | ||
I totally agree with you Monte. I had a look at my assembled collection of templates with this in mind and tried to reduce the curly bracket count.
The one exception I make to the logic rule is when the logic is very closely bound to the visual representation. For example, I have a number of pages with very different designs on my site, and I pass in a PHP sniff object so they can differentiate between browsers, this is never for functionality, only display.
One page (http://aftnn.org/mail/) lines form controls up to a background image. Obviously this is never going to work perfectly across all browsers, so I declare an array of size values for IE Windows and another for the Mac and Netscape. This array only needs to be changed if the design changes, so it's in the template.
Of course, I have the freedom of being both designer and developer so I don't have to ward anyone away from my template logic.
Ben
On Wednesday, July 24, 2002, at 09:03 , Monte Ohrt wrote:
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:(q) Ben Godfrey? (a) Developer and Designer, See http://aftnn.org/ for detailsMaybe 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