views:

160

answers:

3

How do I cache everything on a Smarty template page except for a small portion of the content (which is truly dynamic)?

A: 

You can put the party to be cached into a separate template, and fetch its content with fetch() from the other template.

Zed
+1  A: 

Sort of building on Zed's answer - if your "dynamic" content has a finite number of permutations, build separate templates for those permutations, and fetch() them based on some variable. Something like:

<html>
<body>
<p>Common content would go here with other Smarty {$variables}.</p>

<p>You could then fetch other content using
{if $var1 eq 'foo'}
    {fetch file='/path/to/foo.tpl'}
{elseif $var1 eq 'bar'}
    {fetch file='/path/to/bar.tpl'}
{/if}
</body>
</html>

If you really don't want the included files cached, you'd have to set up some sort of exclusion logic to ensure that those sub-templates aren't cached.

However, if you have an indefinite number of potential dynamic options, you might have to just build the HTML in your PHP code and pass it to Smarty as a view variable.

angrychimp
A: 

You can use Smarty's insert function.

http://www.smarty.net/manual/en/language.function.insert.php

You build a function that gets called and inserts dynamic content in the page. Good for shopping carts, for example.