http://www.perlmonks.org?node_id=417778


in reply to Html Template CSS and CGI PERL

Put a link element in the header of your template file:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN"> <html> <head> <title><TMPL_VAR NAME=TITLE></title> <base target="_self"> <link rel="stylesheet" type="text/css" href="External.css"> </head> <body> .... </body>

You could go a step further and dynamically change your stylesheet by using a template variable for the sytlesheet filename.

For even more flexibility, use template toolkit instead of HTML::template. This would give you the ability to put variables in a stylesheet file, which would be processed before rendering to the browser:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN"> <html> <head> <title>$Page.title</title> <base target="_self"/> <style type="text/css"> <!-- @import 'path/to/css/main.css'; [% PROCESS "path/to/css/theme.css" %] body { font-size: ${font_size}pt; } p { font-size: ${font_size}pt; } --> </style> </head> <body> .... </body> </html>

In the above example, the main stylesheet is imported, a stylesheet with variables (theme.css) is included, and then additional styles are explicitly added to override those in the first two stylesheets.

A drawback with this method is that the styles from theme.css show up when a user looks at the page source, because those styles get embedded in the html document.

Anne