head generation

From: Date: Thu, 27 Sep 2001 08:47:07 +0000
Subject: head generation
Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-1559@lists.php.net to get a copy of this message
Hello, I'd like a feature in Smarty where the contents of the <head></head> of a webpage is generated dynamically, but after all other tags have been parsed. To explain, here's an example. I created a custom function for easy use of images that change on mouseover. ({mouseover on="imgon.gif" off="imgoff.gif}) Now, when a template designer uses this tag, automatically the text '<script language="javascript" src="js/mouseover.js"></script>' should be added to the head, since that is required for the mouseovers to work. Additionally, if the designer uses the tag more than once, this javascript should occur just once in the header. I've solved this now by creating a function register_javascript('js/mouseover.js') in php, that is called when the tag {mouseover} is used. The register_javascript function puts the javascript in a global $g_javascripts array. After Smarty has finished generating the page, I write the header in the already processed page (with a simple str_replace). This works nicely for me, but it breaks when I turn on caching. Because the {mouseover} tag is no longer processed in the cached version, the $g_javascripts array does not contain the correct javascripts. To fix this, the header should be generated before the page is written to the cache, but after all tags have been processed. (This could also be used for automatic initialisation of Smarty's overlib functions.) Is it possible to implement such a feature? Or would you be willing to incorporate this into Smarty if I develop it myself? Greetings, Ivo -- Ivo Jansch <ivo@ibuildings.nl> ibuildings.nl BV - information technology http://www.ibuildings.nl

« previous php.smarty.general (#1559) next »