+# use path from cgi script to support templates in subdirs
+sub url_ex {
+ my $q = shift || die "suff2file needs CGI object!";
+ my $tpl = shift || die "url_ex needs template name!";
+ return suff2file($BASE_PATH, $q->url(-path => 1),$TEMPLATE_PATH,$tpl);
+}
+
+sub suff2file($$$$) {
+ my ($base_path, $p, $path, $tpl) = @_;
+
+ return $tpl if (! $base_path);
+
+ # strip everything to and including base path, leaving only
+ # additional (virtual) path
+ if ($p =~ s,^.*?$base_path,,) {
+ $p =~ s,/*,,g;
+ my ($name,$ext) = split(/\./,$tpl);
+ $p = $name . $p . "." . $ext;
+ } else {
+ # if unable reset it!
+ $p = $tpl;
+ }
+
+ if ( -e "$path/$p") {
+ return $p;
+ } else {
+ return $tpl;
+ }
+
+}