Re: [SMARTY] Seperation of Logic and Presentation

Evan Wagner <[email protected]>
Newsgroups gmane.comp.php.smarty.general
Message-ID <[email protected]>
{quote =Jonathan} I always call the .php page and associated .tpl file
the EXACT same thing.{/quote}

Yeah, that saves brain power bigtime. I hate having to search through
a large smarty template for the page I need. It looks like i'll be
having a file for each page now lol. But i'll still keep just one
parser file. I like 1 parser file because there's not a lot of code
and it's easy to navigate that way.

On 7/29/05, Jonathan Villa <[email protected]> wrote:
> 
> 
> typically, my pages look like this
> 
> if page is called main.php:
> 
> 
> function doSomething(){
> $name='Jonathan';
> $smarty->assign('name',$name);
> }
> 
> $smarty->display('header.tpl');
> $smarty->display('main.tpl');
> $smarty->display('footer.tpl');
> 
> you can even do
> 
> $smarty->display('header.tpl');
> $smarty->display('subnavigation.tpl');
> $smarty->display('main.tpl');
> $smarty->display('footer.tpl');
> 
> granted that your HTML is consistent... i.e.
> 
> in header.tpl you would do
> 
> <html>
> <head>
> <title></title>
> </head>
> <body>
> <table>
> <tr>
> <td>
> 
> 
> and in footer.tpl you would do
> 
> 
> </td>
> </tr>
> </table>
> </body>
> </html>
> 
> I always call the .php page and associated .tpl file the EXACT same thing.
> 
> 
> 
> 
> 
> 
> -Jonathan
> 
> <quote who="Evan Wagner">
> > That's an interesting method. I like all my logic/functions in one
> > file. I hate dealing with a bunch of files. I do see an advantage to
> > having multiple template files because it would allow me to edit
> > things faster.
> >
> > Once again this brings up a question of how to handle <head> only
> > elements that would go into the script before <body> where you would
> > typically include a page into a template. I know you can declare
> > another <head> but that's not going to be  very good in the eyes of a
> > validator script.
> >
> > Maybe two templates per pages. One for head and one for body. I hate
> > repeating code lol
> >
> > On 7/29/05, Jonathan Villa <[email protected]> wrote:
> >>
> >> Personally, I have 2 files for every viewable file... the .php file which contains
> >> all of my logic for that action/page and the template (.tpl) which renders my
> >> page.
> >> the .php page does the neccessary $smarty->assign() or $smarty->register_object,
> >> etc...
> >>
> >> I like this method because my pages don't get consumed with code/logic... the
> >> code/logic on the page is specific for the action... and the .tpl only renders...
> >>
> >>
> >>
> >>
> >>
> >>
> >> -Jonathan
> >>
> >> <quote who="Evan Wagner">
> >> > I've been using Smarty for a couple years now. Recently I've
> >> > questioned my method of separating Logic and Presentation and have
> >> > come up with two ways to solve it.
> >> >
> >> > Current Setup:
> >> >
> >> > 1 Parser file: index.php (Calls upon functions to run for pages via
> >> > _GET variables)
> >> >
> >> > 1 Functions file: This file contains all functions used in the application
> >> >
> >> > 1 template file: index.tpl in the templates directory. This template
> >> > file contains logic within itself such as {if $smarty.get.action
> >> > =="page"} Do Page {/if}
> >> >
> >> > This current situation doesn't seem pragmatic to me.
> >> >
> >> > ALTERNATIVES:
> >> >
> >> > Alternative 1:
> >> >
> >> > 1 Parser file: index.php for example to handle the different _GET
> >> > variables and tell smarty to parse a different template file for each
> >> > _GET page.
> >> >
> >> > 1 Functions File: Contains all functions used in application
> >> >
> >> > Numerous Template Files: The parser file will call upon
> >> > templates/page.tpl as defined in the parser file and for consistency
> >> > of layout I would use {include header.tpl} and {include footer.tpl} in
> >> > each page. This reduces the amount of logic in the template file and
> >> > reduces size of template file.
> >> >
> >> > Alternative 2:
> >> >
> >> > 1 Parser file: index.php will handle all the _GET page logic to call
> >> > upon correct functions via the different _GET variables.
> >> >
> >> > 1 Function file: Contains all functions of application
> >> >
> >> > 1 Primary layout template that will have logic in if such as this:
> >> > {if $smarty.get.action =="page"} {include page.tpl} {/if}
> >> > This still includes logic but reduces the complexity of the template
> >> > by minimizing visible code.
> >> >
> >> >
> >> > OVERVIEW:
> >> >
> >> > I theory I think Alternative1 is better than Alternative2 because it
> >> > reduces the logic within the template. Basically keeps your template
> >> > from doing as much logic as it's better to separate your logic and
> >> > presentation.
> >> >
> >> > What do you guys think?
> >> >
> >> > --
> >> > Smarty General Mailing List (http://smarty.php.net/)
> >> > To unsubscribe, visit: http://www.php.net/unsub.php
> >> >
> >> >
> >>
> >> --
> >> Smarty General Mailing List (http://smarty.php.net/)
> >> To unsubscribe, visit: http://www.php.net/unsub.php
> >>
> >>
> >
> > --
> > Smarty General Mailing List (http://smarty.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
> 
> --
> Smarty General Mailing List (http://smarty.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
>

-- 
Smarty General Mailing List (http://smarty.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.