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

Using variable in plugins with nocache

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


Joined: 31 Dec 2015
Posts: 2

PostPosted: Thu Aug 25, 2016 2:56 pm    Post subject: Using variable in plugins with nocache Reply with quote

I display ads on various pages of my website by using a custom {ads} plugin. Although the pages are cached, I want a new ad to be loaded anytime a page is opened, even if that page is already in the cache. I use the custom plugin shown below

Code:
{ads category=$category nocache}


This is the problem...
Anytime a page is reloaded the category parameter is empty and the plugin cannot function as intended. I would like a way to cache the "category" variable as well so it is passed to the custom plugin everytime it runs.

Thanks
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1642

PostPosted: Thu Aug 25, 2016 3:19 pm    Post subject: Reply with quote

You must ensure that all variables used in {nocache}{/nocache} blocks are assigned to the template before rendering.
If you have something like
Code:
if(!$smarty->isCached(cacheKey))
{
 $smarty->assign(...);
}


you should split it in two sections. Dynamic vars that are always assigned and cached vars that can be left out.
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