Template architecture with CGI

I have a webpage that needs to display a sqlite database. Right now I am dynamically creating an entire page via CGI. However, I would rather have one html file and just populate the table in the file with the database contents. What's the best way to do this? I am limited to html, javascript and CGI in C.

Any help is greatly facilitated.

Thank! Tom

0


source to share


2 answers


If your content is updated once a day (or an hour, etc.), you can schedule the C code as a separate application via cron to run. It reads the html header in the template file, generates the table from the database, and then copies the "footer" html template file. This generated file is copied to the webserver location you want, then the webserver can just serve the HTML file.

If you don't have cron, you can move C to CGI C code, which you can invoke manually via a "hidden" url that generates an HTML file in the same way.



If the table is updating all the time, just do the above, but return the data to the user, rather than create a file for static maintenance.

I'm assuming you don't have access to any type of backend applications (embedded web server?).

+1


source


How much work do you have? Do you have your sqlite connection working in your C code? Writing a simple CGI application is not difficult, just output your headers, especially Content-Type and preferably Content-Length (if you know that), and then just output the page.



As far as the templating system is concerned, you can write html files and replace certain tags with dynamic content. Take a look at some templating systems like Smarty for some inspiration.

0


source







All Articles