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

Cached subtemplate with data lazy loading

Post new topic   Reply to topic    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
Smarty n00b

Joined: 17 Jul 2016
Posts: 1

PostPosted: Sun Jul 17, 2016 11:02 am    Post subject: Cached subtemplate with data lazy loading Reply with quote

I believe some had to resolve this already, but I cannot find it over internet. Maybe I'm entering improper search queries.

At the beginning I want to note, I made such feature for smarty2. Now I'm trying to move to Smarty3. I have it already working too, but I'm fighting with single issue simultaneously looking for better possible solution.

Basic idea is to be able to:
1. include sub-templates with caching
2. call some method (function, static method etc, let's call it 'TplFiller') to fill the sub-template with data, only if cache is invalidated
3. TplFiller can force smarty to return 'nothing' in specific situation. This empty result has to be cached. It can be used if no data are found, then I don't want to render the block at all (it might contain some graphical items, borders etc).
4. control cache groups and ttl from templates
5. pass some parameters to TplFiller and sub-template
6. In case of error thrown from inside of TplFiller (exception), already existing cached data should be used

As I already wrote, I did something which works like requested. Call to this looks like:
{include_c file='template_name.tpl' function='StaticClass::Method' cache_group='abcd' cache_time=2h VAR1='some value' VAR2='another value' etc}

First of all it's my custom solution, it's old, probably dirty. Does exist something similar which might be considered official/complete?

Second thing is #3 feature of requested functionality. I have problem to find out how to force Smarty3 to cache empty result. I figured already out how to return empty result but don't know how to make it cached.

I changed Smarty_Internal_TemplateBase::_execute method (which is private btw so cannot be overlridden). Probably the modification can be moved to Smarty_Internal_Template::render, but right now I have no idea know how to create own class inherited on it, and force Smarty3 to use this class.

With regards

I just figured out, I can force outputting empty content by using output filter. Don't know if it's good approach but it works so far.
Any suggestion, comments are still welcome.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> General 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