Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://989897]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2018-06-19 00:14 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (111 votes). Check out past polls.