Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

{nocache} / assign nocache

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Smarty 3
View previous topic :: View next topic  
Author Message
Perino
Smarty Rookie


Joined: 21 Jul 2010
Posts: 9

PostPosted: Wed Jul 21, 2010 6:42 pm    Post subject: {nocache} / assign nocache Reply with quote

As this is my first post, let me see if i can explain my problem accurately. This is what I'm trying to do:

PHP:
Code:

$oSmarty = new Smarty();
$oSmarty->setCaching( true );

if ( ! $oSmarty->isCached( 'testCache.tpl' ) ) {
  $oSmarty->assign('a','aa');
}

$oSmarty->assign('test','blaat',true);
$oSmarty->display('testCache.tpl');


TPL:
Code:

{$a}<br />
{$test}


The problem is that the {$test} value is only displayed once, before it's cached. Once it's cached the {$test} value will never be displayed. The {$a} value works as expected.

I also tried a {nocache}{/nocache} section with the {$test} in between, but that doesn't seem to work either.

Is this me using the features wrong, or is it a bug? If it's me using the feature wrong, how would i accomplish a template where some variables are cached ({$a}) and some are always populated ({$test})? [/code]

--edit--
I'm running RC3
Back to top
View user's profile Send private message
ucntkilme
Smarty Regular


Joined: 03 Sep 2007
Posts: 84

PostPosted: Wed Jul 21, 2010 6:54 pm    Post subject: Reply with quote

brought from the smarty manual:

<?php
require('Smarty.class.php');
$smarty = new Smarty;

$smarty->caching = 1;

if(!$smarty->is_cached('index.tpl')) {
// No cache available, do variable assignments here.
$contents = get_database_contents();
$smarty->assign($contents);
}

$smarty->display('index.tpl');
?>
_________________
FCKit V1. : http://www.smarty.net/forums/viewtopic.php?t=17748
Back to top
View user's profile Send private message
Perino
Smarty Rookie


Joined: 21 Jul 2010
Posts: 9

PostPosted: Wed Jul 21, 2010 6:55 pm    Post subject: Reply with quote

That's Smarty 2 syntax + not my bug.. Thanks for the reply though Smile
Back to top
View user's profile Send private message
ucntkilme
Smarty Regular


Joined: 03 Sep 2007
Posts: 84

PostPosted: Wed Jul 21, 2010 7:14 pm    Post subject: Reply with quote

Okay so I just downloaded RC3, ive been reviewing the readme that came along with it...

perhaps you can try:

{$test nocache=true} in your tpl

or perhaps change your line of code to this

if ( ! $oSmarty->isCached( 'testCache.tpl' ) ) {
$oSmarty->assign('a', 'aa');
} else {
$oSmarty->assign('test', 'blaat');
}

$oSmarty->display('testCache.tpl');

and now I remember the reason why i didnt use 3, it's because of my use of: {cycle values='alt_bg,alt_bg1'} to alternate row colors in my table...
_________________
FCKit V1. : http://www.smarty.net/forums/viewtopic.php?t=17748
Back to top
View user's profile Send private message
Perino
Smarty Rookie


Joined: 21 Jul 2010
Posts: 9

PostPosted: Wed Jul 21, 2010 7:22 pm    Post subject: Reply with quote

The nocache=true parameter in the tpl is actually the third parameter in the PHP assign ( 'test', 'blaat', true). I tried assigning the var from the tpl {assign var ="test" value = "blaat" nocache=true} but that does not work either.

The other thing you're suggesting does not make sense. The test variable needs to be set at all times, otherwise it won't display.

The cycle thing works fine in Smarty 3 btw Wink.
Back to top
View user's profile Send private message
ucntkilme
Smarty Regular


Joined: 03 Sep 2007
Posts: 84

PostPosted: Wed Jul 21, 2010 7:26 pm    Post subject: Reply with quote

but by what you said, i get that you only want it to display if the page is not cached...

"Once it's cached the {$test} value will never be displayed."

and i tried S3 like a week ago or so, as soon as i loaded my page (without any major changed code involved, as i dont use a lot of it anywho), all i got were errors due to the cycle, when i removed that -- works perfectly however.

it could be that the new one has been changed from the old one -- i suppose i could change to smarty 3, but use that old plugin instead and see if that works but yeah...

im confused as to what it is you really are looking to do. hence the line above i quoted from your OP
_________________
FCKit V1. : http://www.smarty.net/forums/viewtopic.php?t=17748
Back to top
View user's profile Send private message
Perino
Smarty Rookie


Joined: 21 Jul 2010
Posts: 9

PostPosted: Wed Jul 21, 2010 7:37 pm    Post subject: Reply with quote

I'm trying to display a page where some variables are cached and some variables are populated on every request.

In my example the $a is cached, but the $test should be populated on every request (not cached).

Am I making more sense now?
Back to top
View user's profile Send private message
ucntkilme
Smarty Regular


Joined: 03 Sep 2007
Posts: 84

PostPosted: Wed Jul 21, 2010 7:49 pm    Post subject: Reply with quote

well it makes more sense to me now, though mohrt will be better to answer that than me.. though had to try.. sorry i didnt ;(
_________________
FCKit V1. : http://www.smarty.net/forums/viewtopic.php?t=17748
Back to top
View user's profile Send private message
Perino
Smarty Rookie


Joined: 21 Jul 2010
Posts: 9

PostPosted: Wed Jul 21, 2010 7:51 pm    Post subject: Reply with quote

Thanks for trying Smile
Back to top
View user's profile Send private message
U.Tews
Administrator


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

PostPosted: Wed Jul 21, 2010 9:15 pm    Post subject: Reply with quote

nocache variables must be assigned before the isCached() call.
Back to top
View user's profile Send private message
Perino
Smarty Rookie


Joined: 21 Jul 2010
Posts: 9

PostPosted: Wed Jul 21, 2010 9:18 pm    Post subject: Reply with quote

Thanks, that works Smile.
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    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