Page 1 of 1

[SOLVED] content not loading with smarty cache enabled

Posted: Thu Aug 09, 2012 1:43 am
by rotezecke
After the upgrade from 1.10.3 to 1.11 i have a problem on two templates that use multiple content blocks that are wrapped in an if statement:

Code: Select all

{content block="tab_one" label="Title for 1st tab" assign=tab_one oneline="true"}
{if !empty($tab_one)} <div class="pane" id="pane1"> {content block="pane_one" label="Content for 1st pane"}</div> {/if}

{content block="tab_two" label="Title for 2nd tab" assign="tab_two" oneline="true"}
{if !empty($tab_two)} <div class="pane" id="pane2">{content block="pane_two" label="Content for 2nd pane"}</div> {/if}

and so on.
however, with [edit] smarty [end edit] caching enabled, anything wrapped in these type of if statements don't load. (view page source - content not there). browser thinks page loaded successfully. when I disable the if statement things work/load fine. Is there a syntax error in the if statement?

EDIT: I tried empty() with not and !, then tried different styles of qualifiers (!= ne neq) '' (leaving spaces on either side). still no luck.

Edit: 1.10.3 defined IF_FUNCS in
/lib/smarty/Smarty.class.php

Code: Select all

    var $security_settings  = array(
                             'PHP_HANDLING'    => false,
                             'IF_FUNCS'        => array('array', 'list',
                                                               'isset', 'empty',
                                                              'count', 'sizeof',
                                                            'in_array', 'is_array',
                                                          'true', 'false', 'null'),
                                 'INCLUDE_ANY'     => false,
                                   'PHP_TAGS'        => false,
                                'MODIFIER_FUNCS'  => array('count'),
                                  'ALLOW_CONSTANTS'  => false,
	                                    'ALLOW_SUPER_GLOBALS' => true
                                  );
1.11 does not. Relevant?

Cheers, Mario

CMSMS 1.11
CMSMailer 5.2.1
FileManager 1.4.0
MenuManager 1.8.2
ModuleManager 1.5.5
News 2.12.7
Search 1.7.6
TinyMCE 2.10.1
CGSimpleSmarty 1.5.2
CGExtensions 1.30
CGBlog 1.9.8
CGFeedback 1.5.7
Captcha 0.4.5
FormBuilder 0.7.3
IE6Warning 1.03
Showtime 3.2
CMSPrinting 1.0.2

Server: Linux Debian Lenny 2.6.26-1-686 kernel
apache 2.2.9-10
mysql 5.0.51a-24
php 5.2.6-1

Re: content not loading with smarty cache enabled

Posted: Thu Aug 09, 2012 3:28 am
by calguy1000
Do you mean the 'Enable Smarty Caching' checkbox on the "Smarty Settings" tab of the "Global Settings" page?

Re: content not loading with smarty cache enabled

Posted: Thu Aug 09, 2012 3:55 am
by rotezecke
Yes, Site Admin -> Global Settings -> Smarty Settings

When "Enable Smarty Caching" is set to "Yes" the content does not load. (I tried all other possible combinations of the three settings below). I also removed many if not most plugins, global content, and what not from my template to see if it makes a difference and also tried nocache here and there.

http://forum.cmsmadesimple.org/viewtopi ... 8&p=283831

Here's a similar report, but in my case removing the if statement from around the additional content blocks, fixes it. (But of course, i'd like to keep my if statements). All other if statements work fine.

Setting "Enable Smarty Caching" to "No" also works (content is loaded).

Re: content not loading with smarty cache enabled

Posted: Thu Aug 09, 2012 3:56 am
by calguy1000
I just tested this, and it is correct. With Smarty caching enabled the compiled/cached php code will not have the logic to hide the output...

Solution Surround your logic with {nocache} and {/nocache}
i.e:

Code: Select all

{nocache}
{content block='Sidebar' assign='tmp'}
{if $tmp != ''}
  <div id="sidebar">
  {$tmp}
  </div>
{/if}
{/nocache}
Edit: More information here: http://docs.cmsmadesimple.org/general-i ... g-in-cmsms

Re: content not loading with smarty cache enabled

Posted: Thu Aug 09, 2012 4:29 am
by rotezecke
Thanks heaps. Works fine now.

Re: [SOLVED] content not loading with smarty cache enabled

Posted: Fri Aug 10, 2012 11:32 am
by cypher6x
Does the assign have to be wrapped in the {nocache} as well or just around the {if} construct?

I tend to have all my assigns at the top of the template and logic further down the page.

Re: [SOLVED] content not loading with smarty cache enabled

Posted: Fri Aug 10, 2012 4:59 pm
by calguy1000
I am not sure. I would tend to think (based on my knowledge of smarty) that it has to be around the logic.