PGHtml
HTML template engine using PostgreSQL
PGHtml is a command line utility that creates HTML, JS, JSON and other types of files using data retrieved from PostgreSQL database
Tool is described in more detail on a separate website pghtml.org
Tool is designed to display on the site static information from database, which:
- is rarely updates (e.g. dictionaries)
- preparation takes a long time
- does not require real-time relevance (e.g. TOP products)
PGHtml is a service that creates HTML, JS, JSON and other file types using data obtained from a PostgreSQL database.
The file is created from a template file in which SQL queries, tags and variables are replaced.
Template extension started with pg, i.e. index.html will be created based on the index.pghtml file
Replacements
| $$ [SQL query] $$ | — | SQL query result |
| <pghtml-include> | — | file contents |
| ${[variable]} | — | variable value |
<!-- single value from database --> $$ select user $$ <!-- multiple values --> $$ select tablename from pg_tables where schemaname='pg_catalog' limit 5 $$ <!-- inclusion file example_include.html --> <pghtml-include>include-simple.html</pghtml-include>
→
→
<!-- single value from database --> postgres <!-- multiple values --> pg_statistic pg_type pg_foreign_server pg_authid pg_statistic_ext_data <!-- inclusion file example_include.html --> [ file example-header.html ]
Template
<!DOCTYPE html> <head> <title>${title}</title> </head> <body> <h2>${caption}</h2> ${text} </body> </html>
Source and result pages
<pghtml-var name="title">Example</pghtml-var> <pghtml-var name="caption">Multiline text</pghtml-var> <pghtml-var name="text"> Text line 1 <br> <i>Text line 2</i> </pghtml-var> <pghtml-include>/template/template-common.html</pghtml-include>
→
→
→
<!DOCTYPE html> <head> <title>Example</title> </head> <body> <h2>Multiline text</h2> Text line 1 <br> <i>Text line 2</i> </body> </html>
<!-- single value from database --> $$ select user $$ <!-- multiple values --> $$ select tablename from pg_tables where schemaname='pg_catalog' limit 5 $$ <!-- inclusion file example_include.html --> <pghtml-include>include-simple.html</pghtml-include>
→
→
<!-- single value from database --> postgres <!-- multiple values --> pg_statistic pg_type pg_foreign_server pg_authid pg_statistic_ext_data <!-- inclusion file example_include.html --> [ file example-header.html ]
Check for updates
- if contents of resulting file have not updated, then the file is not overwritten and web server does not redeploy itImport
- support for importing other files (such as HTML fragment or JSON data)Change list
- it is possible to create list of changed filesError handling
- if an error occurs (for example, when executing a SQL query), processing continues, extended information is output to log (stderr) and at end of execution, the tool returns the code of unsuccessful execution to OS. This allows you to configure monitoring of data updates on the siteSelecting processed files
- possible processing of specific files, directories with recursion and setting file prefixes. At same time, built-in variables are created that can be used in referencies and in SQL queries. Usually root directory of site is specifiedVariables
- support variables from the command line, built-in variables (directories, paths to files, etc.) and tag attributes when importing fileUnlimited nesting
- support including files inside an included file, redefining variables multiple times and using them inside another variableConditions and loops
- programming inside files not supported, PostgreSQL stored procedures are used to implement logic