Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.

Caching with cache id

 
Post new topic   Reply to topic    Smarty Forum Index -> Smarty 3
View previous topic :: View next topic  
Author Message
Karel S.
Smarty Rookie


Joined: 03 Aug 2009
Posts: 26
Location: The Netherlands

PostPosted: Wed Sep 02, 2009 7:56 am    Post subject: Caching with cache id Reply with quote

I'm trying to cache some product pages. Because all products have the same template, I must use the productid as cache id.

Code:

$smarty->caching = 1;

$aTemplate[$iProductId] = 'product_view';

if ( !$smarty->is_cached ( 'product_view.tpl', $iProductId ) )
{
// do querys and assign data
}

// bla

reset ( $aTemplate );
$iTemplateId = key ( $aTemplate );
$sTemplateName = current ( $aTemplate );

if ( $iTemplateId > 0 )
   $smarty->assign ( 'sModuleContent', $oSmarty->fetch ( $sTemplateName . '.tpl', $iTemplateId ) );
else
   $smarty->assign ( 'sModuleContent', $oSmarty->fetch ( $sTemplateName . '.tpl' ) );


I get a template without the assigned values. When I take a look into the cache dir, I can only find this file:

1318663443.product_view.tpl.php

I seems that Smarty don't set the cache id?
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5067
Location: Hamburg / Germany

PostPosted: Wed Sep 02, 2009 3:05 pm    Post subject: Reply with quote

Smarty3 introduced a concept of template and data objects which can have a parent child relationship. for this an additional paramter 'parent' was introduced which did change the parameter order of fetch and display to
($template, $parent = null, $cache_id = null, $compile_id = null)

So
$oSmarty->fetch ( $sTemplateName . '.tpl', null, $iTemplateId )
should work.

I see the point that this does it more difficult to upgrade from Smarty2 to Smarty3. Also it might be pssible that it will be more likely that users will use cache_id and Compile_id as use template or data object chaining. It could make sense to change the parameter ordering. We have to discuss.
Back to top
View user's profile Send private message
Karel S.
Smarty Rookie


Joined: 03 Aug 2009
Posts: 26
Location: The Netherlands

PostPosted: Wed Sep 02, 2009 3:16 pm    Post subject: Reply with quote

Ah, ok. Testing right now ...

Quote:
I see the point that this does it more difficult to upgrade from Smarty2 to Smarty3.


It's not difficult. The problem is, I can't find any documentation about the new Smarty 3 features and changes the way Smarty 3 works. A manual or API doc should make upgraden a lot easier.

The only documentation available is here, but that is out-dated.
Back to top
View user's profile Send private message
douglassdavis
Smarty Junkie


Joined: 21 Jan 2008
Posts: 541

PostPosted: Fri Sep 04, 2009 9:11 pm    Post subject: Reply with quote

U.Tews wrote:
Smarty3 introduced a concept of template and data objects which can have a parent child relationship. for this an additional paramter 'parent' was introduced which did change the parameter order of fetch and display to
($template, $parent = null, $cache_id = null, $compile_id = null)

So
$oSmarty->fetch ( $sTemplateName . '.tpl', null, $iTemplateId )
should work.

I see the point that this does it more difficult to upgrade from Smarty2 to Smarty3. Also it might be pssible that it will be more likely that users will use cache_id and Compile_id as use template or data object chaining. It could make sense to change the parameter ordering. We have to discuss.


Could you say more about the parent thing? Is that the same as template inheritance?

I prefer the params in the same place myself Smile But, whatever is best I suppose
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7365
Location: Lincoln Nebraska, USA

PostPosted: Fri Sep 04, 2009 9:50 pm    Post subject: Reply with quote

The params are getting switched in SVN to match Smarty 2 very soon.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Smarty 3 All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP