Joe Rhett wrote:
> To be honest, one of the huge problems OpenSRS has is the dependancy upon
> the template names - template names in templates right beside template names
> in the code.
>
> If you designed it better, you wouldn't need to have any template names in
> the code at all -- absolutely no dependacies. The template directory could
> be copied directly into the document root and modified as much as anyone
> could desire. It's just a starting point.
>
> (Note that I'm not just dreaming this --- all of our commercial
> applications function in this fashion. They must, since the web developers
> have no access to the source code)
Might I recommend a better templating solution that makes it easier to separate
the template from the code?
OpenSRS does not have this separation between code and template right now. The
templates you are using sorely lack a block IF construct. For example, on the
verify page in reg_system.cgi, you have a function build_tech_verify that
builds the HTML for the technical verify section (which shows up depending on
configuration):
# pass along the tech contact info if the conf file tells us to
if ($REG_SYSTEM{custom_tech_contact}) {
$HTML{TECH_CONTACT} = build_tech_verify(\%in);
}
The sub build_tech_verify looks like this:
sub build_tech_verify {
my $data = shift;
if ($data->{tech_address2}) { $data->{tech_address2} .= "<br>\n" }
if ($data->{tech_address3}) { $data->{tech_address3} .= "<br>\n" }
my $html = <<EOF;
<tr><td colspan=2 align=center><b>Tech Contact Information</b></td></tr>
<tr>
<td valign=top>
$data->{tech_first_name} $data->{tech_last_name}<BR>
$data->{tech_org_name}<BR>
$data->{tech_address1}<BR>
$data->{tech_address2}
[[snip]]
</td>
</tr>
EOF
return $html;
}
Instead, you should move the HTML from buld_tech_verify into the template, and
pass the custom_tech_contact configuration and use it to control a conditional
block in the template. Something like this in the code:
$HTML{show_tech_contact} = $REG_SYSTEM{custom_tech_contact};
And this in the template:
[% IF show_tech_contact %]
<tr><td colspan=2 align=center><b>Tech Contact Information</b></td></tr>
<tr>
<td valign=top>
$data->{tech_first_name} $data->{tech_last_name}<BR>
......
[% END %]
You are also doing something similar with this code in do_setup_profile in
reg_system.cgi:
$HTML{domains} = join "<br>\n", @domains;
The separator between the domains should be controlled by the template, not the
code. If you had a better templating solution (like the Template-Toolkit module
from CPAN), you could write the code like this:
$HTML{domains} = [ @domains ]; # pass a list of domains to the template
Then in the template:
[% FOREACH domain = domains %]
[%$domain%]<br>
[% END %]
Then you allow the flexibility for people to modify just the template to be
something like:
<ul>
[% FOREACH domain = domains %]
<li>[%$domain%]
[% END %]
</ul>
..and when you release a new version of the client code, their modified
template still works!
You really need a higher power templating system than what you are using right
now. Let me make some recommendations. :-) (If you'd like more information,
search the archives of the [EMAIL PROTECTED] list where there was just a big
discussion about HTML template modules.)
Right now I'm using Template-Toolkit from CPAN and it is wonderful. It was
designed to help you implement this separation between code and template that
we've been talking about.
http://search.cpan.org/search?dist=Template-Toolkit
Also perhaps read:
http://www.mail-archive.com/modperl@apache.org/msg09774.html
which is a recent post by the author on the [EMAIL PROTECTED] talking about
Template-Toolkit. For more of the thread see:
http://www.mail-archive.com/modperl@apache.org/thrd2.html
Another good solution is HTML-Template, which I've used before but found myself
a little too hemmed in by the template for my own tastes:
http://search.cpan.org/search?dist=HTML-Template
Hope this helps.
David Harris
President, DRH Internet Inc.
[EMAIL PROTECTED]
http://www.drh.net/