in reply to Why use templates?

Which leads me to my arguement against templates.

Your argument is flawed because it assumes people only use templates to build HTML, when templating is applicable to so much more.

    --k.


Replies are listed 'Best First'.
Re: Re: Why use templates?
by Fletch (Bishop) on Apr 18, 2002 at 15:49 UTC

    Very good point. At a previous job I used perl to generate m4 (a `traditional Unix macro processor'), arguably a form of templating. The m4 was part of the Solaris package installation process for the product and was executed on the machine upon which the software was being installed (otherwise I probably would have just sent perl, this being in the days before perl shipped stock with Solaris :).

    Recently I've taken to using Template Toolkit in place of m4 for generating config files based on dynamic data (network monitoring using Nagios for 70+ (and growing quickly) remote boxen and routers). There's nothing remotely HTML related about it, it's just much simpler for me to say `type this to add a new host':

    [% host( name="foo", addr="10.1.1.99" ) %]

    than it would be to make everyone learn how to (reliably, without typos) produce:

    define host{ host_name foo alias foo address 10.1.1.99 check_command check-host-alive max_check_attempts 3 process_perf_data 0 retain_nonstatus_information 0 notifications_enabled 0 notification_interval 120 notification_period 24x7 notification_options d,u,r,n }

    (Yes, I'm aware Nagios has a form of templating internally, but that can't be driven externally with perl logic. This way I can make the macros smarter (e.g. you may see a definition for host bar, but it won't be live yet so there's no point in monitoring it so don't output anything).)