| Daniel Cummings 2004-11-16, 3:58 pm |
| Hi Matthew,
Thank you for your swift reply.
replies inline below...
On 11/15/04 12:14 PM, "Matthew Weier O'Phinney" <matthew@garden.org> wrote:
> * Daniel Cummings <dan@dbmscan.com>:
>
> Do you need to be caching at all? If not, turn off caching, and you
> should should be okay.
yes, i need caching to help deal with some database speed issues. that is
the primary reason i use smarty. that, and the way it helps me keep HTML out
of my PHP code.
> 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.
so i should use fetch() and pass the returned text to a template variable
placed directly in the index template? if i get you right, fetch() in my PHP
code can take the place of an include tag AND i get cache control over it?
. i'll give it a try.
i assume that in this technique, i can no longer cache the index template's
output, but should feed it out 'raw' each request. am i correct in that
assumption? if i left the index template caching in place smarty would just
use the final rendered output text from the display() call and ignore the
fresh/uncached text fetched into template variables. should i turn off
caching just before calling display() as you do in the code below?
> 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');
Oh this looks super! I like the idea of organizing my blocks into objects!
Thanks for the tip.
if you don't hear from me again, that means this advice took care of my
problem...
dan
|