Re: [Phplib-users] Template: How to handle conditional html?
Brought to you by:
nhruby,
richardarcher
From: Lazaro F. <la...@mo...> - 2001-11-27 11:58:35
|
Hi I'm agree with Brian, I have been working with PHP for almost two years now, and actually I was not a new programmer (more than 10 years programming from C to VB), when I started PHP WEB Programming. Based on the experience very soon I realized that mixing PHP with HTML would be a nightmare to maintain, on the other hand we are a team, graphical designer (DW,Flash,etc), core programmer (PHP,SQL,JS,etc), and what we called a site assembler, who put together PHP core classes and functions, and HTML (templates and libs), to build PHP dinamic pages Every page we build is made of two main files .PHP, and .iHTML files, in turn every .PHP main file may include a lot of .INC files ( PHP files with classes and functions definitions ), so the same thing for the iHTML file that may be fill in with a lot of LBI files (HTML blocks) A page is built parsing templates and sub-templates ( HTML blocks ), the last ones are parsed alone and then parsed in as variables within main templates, this layout set the designer 100% percent free from PHP code , and the opposite to, the programmer even know how the DB results or external files information is rendered out i.e: Results from a DB search, are displayed using several blocks or HTML libs, parsed within an iHTML file that shows the page as a whole (header blocks,footers blocks, DB results blocks,etc) Two months ago a client asked us to change the whole look and feel of its new packed site, the task proves to be easy thanks to the site architecture, non PHP page was changed at all, only the iHTML and LBI files (with the HTML) were changed by the designer, better than that, the HTML files are 100% based on CSS files, so the style is separated from the HTML layout, changing the CSS definitions (only one file) the whole site (around 100 HTML files) had a new look and feel (colors,fonts,style,etc). Finally the Sites are almost 100% multi-lingual sites, so using templates also make easier to maintain the same HTML layout to be shown in any language Although developing sites this way involves a lot of extra work in the beginning and after, for us it was a matter of compromise between 'faster to develop' VS 'harder to maintain', as we get more and more client sites to maintain the maintenance time should be keep at a minimum. Lazaro ----- Original Message ----- From: Brian Popp <bp...@ct...> To: 'Menzi, Hans' <HM...@ec...> Cc: Phplib (E-mail) <Php...@li...> Sent: Monday, November 26, 2001 7:04 PM Subject: RE: [Phplib-users] Template: How to handle conditional html? > >>"I am just learning PHP and I would like to know what reasons you have > >>for that statement." > > There's been a lot of discussion about it here on this forum, but my primary > reason for saying that is just personal experience. I built a system when I > first started using PHP. It was fairly complicated(100+ pages) and to be > honest it has worked very well. In that system, almost all the PHP is being > generated dynamically in the PHP. Unfortunately, this system has been a > beast to maintain. When I need to make a very simple cosmetic change, I have > to dig through pages and pages of complicated PHP code. Likewise, when I > need to make a change, even a simple change, to my code, the PHP is > needlessly cluttered with lines and lines of echo/print statements. > > My new way, which works infinitely better, is to use templates almost > exclusively. I create two files for every page, one called xxxx.php and one > called xxxx.html. xxxx.php does all the thinking and xxxx.html just sits > there looking pretty. > > xxxx.php will normally look something like: > > -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= > > include "../globals.php"; > > my_page_open(); > include ABSOLUTE_ROOT . "header.php"; > > $t = new Template; > $t->set_file ( "main", "xxxx.html" ); > > $t->set_var ( "CURRENT_DATE", date ( 'm.d.y h:i:s' ) ); > ... > > $t->parse ( "out", "main" ); // (writes the xxxx.html file to the browser) > > include ABSOLUTE_ROOT . "footer.php"; > my_page_close(); > > -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= > > So if I decide I want to change the date format, it's fairly easy to find it > in the xxxx.php file. Or if I decide I want to make the date fluorescent > pink, I can just pull up the xxxx.html file in Dreamweaver and modify the > formatting on the {CURRENT_DATE} tag. This is admittedly a very simple > example; the real power of templates comes when you start working with > database data, etc. Give templates a try. Once you get comfortable with the > limitations (namely dynamic HTML), I think you'll love how much more > maintainable your code becomes. > > -----Original Message----- > From: Menzi, Hans [mailto:HM...@ec...] > Sent: Monday, November 26, 2001 10:24 AM > To: Brian Popp > Subject: RE: [Phplib-users] Template: How to handle conditional html? > > > "It's normally not a good idea to put HTML in your PHP" > > I am just learning PHP and I would like to know what reasons you have > for that statement. > > -Thanks > Hans Menzi > > > -----Original Message----- > From: Brian Popp [mailto:bp...@ct...] > Sent: Monday, November 26, 2001 11:03 AM > To: 'Peter Holm'; Phplib (E-mail) > Subject: RE: [Phplib-users] Template: How to handle conditional html? > > > True. It's normally not a good idea to put HTML in your PHP, but I think > there's a time and a place. With a very dymamic menu, for example, I'll > usually put a single tag {menu}, and then build the HTML like so: > > function addMenuItem ( $label, $link, $active=false ) > { > $html = "<td>"; > $html .= ($active ? "<B>" : "" ); > $html .= $label; > $html .= ($active ? "</B>" : "" ); > $html .= "</td>"; > > return $html; > } > > $html = addMenuItem ( "Home", "home/", $currentAction=="home" ); $html > .= addMenuItem ( "Links", "links/", $currentAction=="links" ); $html .= > addMenuItem ( "News", "news/", $currentAction=="news" ); > > $t->set_var ( "menu", $html ); > > (I find that if you use functions, the PHP stays very maintainable and > readable. ) > > > -----Original Message----- > From: Peter Holm [mailto:PH...@gm...] > Sent: Saturday, November 24, 2001 10:37 AM > To: Php...@li... > Subject: [Phplib-users] Template: How to handle conditional html? > > > Hi, > > maybe some of you came across this problem also: > > there are somtimes elements of a site, that should be shown only under > certain circumstances, e.g. you have a browsing page with "previous" and > "next" buttons but you don´t wnat the 'previous" button to be shown if > there is nothing before the actual shown item, vice versa you want to > hide the "next"-button, if there is nothing next to show. Maybe you have > different pictures for this situation and maybe, to make it even more > complicated, someone wants you to have a rollover only on the "active" > next/previuos buttons. > > OK, this would be easy usually with some if-statements in the code, but > when using templates, this breaks the sense of them somehow. If you use > something like {NEXT} in your template-file which contains the whole > html for that link ('a href' and img), there is nothing to see in the > template anymore (if someone is generating it with an graphic al tool). > > Otherwise it is not good to use some php-code in the template-file, so I > tend to the first solution, what makes some more work... > > Does anybody have any other ideas about that? > > Thanks for your attention, > Peter > > > Have a nice thread, > Peter > > _______________________________________________ > Phplib-users mailing list > Php...@li... > https://lists.sourceforge.net/lists/listinfo/phplib-users > > _______________________________________________ > Phplib-users mailing list > Php...@li... > https://lists.sourceforge.net/lists/listinfo/phplib-users > > _______________________________________________ > Phplib-users mailing list > Php...@li... > https://lists.sourceforge.net/lists/listinfo/phplib-users > > > |