Plog Template Update – December 13, 2004

It had always annoyed me that you couldn't use smarty commands in the stylesheet files in plog. It turns out it wasn't that hard to figure out, and the original authors had it basically done, but if you believe the comments, didn't think it worked yet.
It is helpful to change /class/template/templateutils.class.php, specifically the "setContentType" function to read:
header("Content-Type: " . $mimeType);

Then, make a file in your template directory called style.css.template and add
{$utils->setContentType("text/css; charset=iso-8859-1")}
to the top of the file. It is important that this call be before any other html/css output (ie. in plugins too), otherwise you will get a PHP error saying that you are trying to modify the headers after the content has already started. In my case, I had written a plugin that had some stray carriage returns at the bottom, and so I had to remove those before this would work.
You should include the stylesheet from your header.template file like this:
templatePage("style.css")}" />
In your stylesheet, instead of using '{' and '}' you will need to use "{ldelim}" and "{rdelim}" because smarty is set up to parse the braces specially.
Then you can use regular smarty commands in your stylesheet files also.

Questions? Have Anything to Add?
(your comments will be published on this site - click here for private questions)

Unfortunately it will probably be not so easy in the next version... We've added support for conditional GET headers (it's optional, but it allows to save some bandwidth since clients will not have to download the whole page if it hasn't changed) so it's important not to mess around with HTTP headers. Of course if you disable support for this feature everything will be fine :)
Posted by oscar on December 16, 2004, 2:07 am

Conditional GET is a good thing, I have been looking into that too, to make things faster. I guess I will have to see if there is a way around it with the next version, because I probably won't want to disable that feature.
Posted by jondaley on December 16, 2004, 9:51 am

The conditional GET feature goes hand in hand with the newly added support for Smarty template caching... I mean, there is no way to determine whether a page has changed since the last time it was visited if you're rebuilding it every time a request comes, right? :) On the other hand, when using Smarty's caching features then we have a saved version in disk and we can compare the timestamp of the cached version with the timestamp in the If-Modified-Since HTTP header sent by the client and react accordingly... But yes, I do agree that it is a good feature. Specially for sites that get thousands of visits a day!
Posted by oscar on December 16, 2004, 1:15 pm

Right on both counts.
I had been thinking about removing more of the dynamic content (# of visitors currently online, etc) in order to be able to cache things better.
I was wondering about keeping track of the timestamp the last time something in the database had been changed, and then returning 304 if the dates were all right.
The last thought I had had was that there is some content that doesn't really matter if it changed, depending on what page you are looking at, so I was wondering how hard it would be to see what content matters for this page, and had figured that was sort of hard, so hadn't thought about it any more.
I wonder if this conversation should be moved to plogworld (if there is anything more to say), to benefit people there too...
Posted by jondaley on December 16, 2004, 1:23 pm