Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Calling functions in middle of CGI HTML declarations

by sundialsvc4 (Abbot)
on Aug 27, 2012 at 00:56 UTC ( #989897=note: print w/ replies, xml ) Need Help??


in reply to Calling functions in middle of CGI HTML declarations

Whereas I would chime in for Template::Toolkit, but the essential point is the same:   you should, insofar as possible, clearly separate program logic from presentation.   If When the marketing department says to you, “that looks great, but can you just ... (insert complete page makeover here),” you should be able to do that just by changing a template.   The program logic builds data structures (and provides functions), then the template iterates through them.   “Separation of concerns.”

Templating systems have considerable power for just this reason.   You can loop through data structures, make decisions, call Perl functions and so-on from within a template.   (Usually, the templating system works by building and compiling a Perl subroutine on-the-fly.)

Postscript:   This is one of the “lessons learned” of the PHP community ... and a hard lesson it was, because the intrinsic design of PHP is originally was very-specifically to allow logic to be embedded into the HTML.   Today, you won’t find any PHP pro doing that anymore (although plenty of legacy apps do and always will remain).   They all use templates now, and objects, and the language and its user-contributed-source libraries have grown in these directions.   While you may still find books that teach that approach, it is now widely recognized as a poor practice for the reasons aforesaid.


Comment on Re: Calling functions in middle of CGI HTML declarations

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://989897]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (7)
As of 2014-12-27 15:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (177 votes), past polls