Re: smarty include tags always cache?

From: Date: Mon, 15 Nov 2004 17:14:00 +0000
Subject: Re: smarty include tags always cache?
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-11965@lists.php.net to get a copy of this message
* Daniel Cummings <dan@dbmscan.com>: > i have a typical website serving left menu block, top block, center block... > etc. > > i currently use smarty include tags to pull in these other blocks to a main > index template. > > i have just realized that the data output from include tags is cached along > with the index page's cache - there seems to be no way to keep the include > tags dynamic. i want to be able to have each block be independent - > specifically the center block should be able to have new data while the left > menu block still build from cache. > > what is the best approach to this problem? Do you need to be caching at all? If not, turn off caching, and you should should be okay. Alternatively... I would create a page template that has placeholder variables for the various content blocks, and then templates for each type of content block. Then, in your script, grab content, pass it to the appropriate content block's template, and use the fetch() method to grab the compiled template contents into a variable. Then pass these variables to the main page template. Using this system, you could turn caching on and off within your script based on the content type. As an example, if $content_blocks contains an array of various content block objects, then: foreach ($content_blocks as $block) { // $block->cache indicates whether or not to cache the block if ($block->cache) { $smarty->caching = 1; } else { $smarty->caching = 0; } // do some processing, assign some variables... // $block->template_file is the name of the block's template // file $block_content = $smarty->fetch($block->template_file); // $block->template_var is the name of the Smarty variable into // which the blocks content will be placed in the main page // template $smarty_page->assign($block->template_var, $block_content); } // Process the main page's content... // Now display the main page $smarty->display('page_template.tpl'); -- Matthew Weier O'Phinney | mailto:matthew@garden.org Webmaster and IT Specialist | http://www.garden.org National Gardening Association | http://www.kidsgardening.com 802-863-5251 x156 | http://nationalgardenmonth.org

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