Configure database connection in config file

Pass the db configuration info to the page templates via the
template constants feature.
This commit is contained in:
Roan Horning 2022-06-29 10:42:10 -04:00
parent b33e812c3d
commit 3d0ddbfe24
No known key found for this signature in database
GPG Key ID: 6E07059BD168E395
2 changed files with 15 additions and 3 deletions

View File

@ -54,14 +54,13 @@ sub main {
# Load config file
read_config "site.cfg" => my %config;
my $tt = get_template_html();
my $tt = get_template_html($config{DBI});
generate_page($tt, $config{correspondents}{navigation}, $config{correspondents}{content});
return 0;
}
sub get_template_html {
sub get_template_html (\%@) {
# For an HTML based Template file, define the
# template start and end tags to also function as
# HTML comments to make the template file valid HTML.
@ -71,6 +70,11 @@ sub get_template_html {
EVAL_PERL => 1,
START_TAG => '<!--%',
END_TAG => '%-->',
CONSTANTS => {
driver => $_[0]{driver},
user => $_[0]{user},
password => $_[0]{password},
}
}) || die $Template::ERROR, "\n";
}

View File

@ -1,3 +1,11 @@
# Configure the Perl DBI driver to allow the templates communicate
# with the database.
# dbi:<driver name [SQLite, CSV, ADO, mSQL, etc.]>:<database name>
[DBI]
driver: dbi:SQLite:hpr.db
user:
password:
# Configure the navigation menu and the content templates for each page
# of the site:
# [page_name]