RE: [Phplib-users] Template: How to handle conditional html?
Brought to you by:
nhruby,
richardarcher
From: Brian P. <bp...@ct...> - 2001-11-26 16:03:03
|
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:=20 function addMenuItem ( $label, $link, $active=3Dfalse ) { $html =3D "<td>"; $html .=3D ($active ? "<B>" : "" ); $html .=3D $label; $html .=3D ($active ? "</B>" : "" ); $html .=3D "</td>"; return $html; } $html =3D addMenuItem ( "Home", "home/", $currentAction=3D=3D"home" ); $html .=3D addMenuItem ( "Links", "links/", $currentAction=3D=3D"links" = ); $html .=3D addMenuItem ( "News", "news/", $currentAction=3D=3D"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:=20 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=B4t 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 |