Re: [SMARTY] caching example

From: Date: Sun, 30 Mar 2003 11:22:58 +0000
Subject: Re: [SMARTY] caching example
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-8994@lists.php.net to get a copy of this message
Hello Paul, Sunday, March 30, 2003, 3:38:01 AM, you wrote: > I have a site that has logins with usernames and ids and stuff like > that. It shows the username on each page. I want to cache stuff, but I > don't want to cache the usernames. What is the easiest way to display a > username or other user specific information while still caching the rest > of the document? I'm aware that I can use insert, but perhaps there is > some other trick that I'm not aware of... I'm currently using a hack like the following: class XSmarty extends Smarty { function recompile () { $output = $this->fetch ($this->filename, $this->cache_id, $this->compile_id); $this->caching = FALSE; $this->left_delimiter = "~|"; $this->right_delimiter = "|~"; $this->template_dir = SMARTY_DIR . "cache"; $this->compile_dir = SMARTY_DIR . "template_cc"; $output = $this->fetch ($this->getCacheFilename ()); return array_pop (explode ("\n", $output, 2)); } } ------------- with a template like: ------------- <ul> {foreach from=$locations item=location} <li>{$location->getTitle()} ~|if $session->hasWritePerm($location->id) eq true|~ <a href="">edit</a> ~|/if|~ </li> {/foreach} </ul> (This example would generate a list of links to locations, where some users have permission to write and some have not - so there would be an additional non-cache [edit] link for some users depending on permissions.) No warranties regarding speed, ressources etc. :) Sven

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