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

Smarty nocache condition

 
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 -> General
View previous topic :: View next topic  
Author Message
MadGreen
Smarty Rookie


Joined: 15 Feb 2021
Posts: 5

PostPosted: Mon Feb 15, 2021 12:25 pm    Post subject: Smarty nocache condition Reply with quote

Back in version 3.1.18 I successfully used this syntax:
Code:
{nocache}{if (!empty($smarty.session.user_id))}{/nocache}
    <script>{literal}
        alert ("!");
    {/literal}</script>
    {$cashed_var}
{nocache}{/if}{/nocache}

It was very convenient to create non-cached conditions inside a cached template. Now (in version 3.1.35) I get an error: Syntax error in template "file:/file.tpl" on line 4 "{literal}" unclosed '{if}' tag in file "/Smarty/libs/sysplugins/smarty_internal_templatecompilerbase.php" at string #4

How can I resolve an issue with a non-cached condition when using the Smarty cache?
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Wed Feb 17, 2021 8:11 am    Post subject: Reply with quote

There's nothing to resolve, it was not working before, you just get a notification about it now.
Back to top
View user's profile Send private message
MadGreen
Smarty Rookie


Joined: 15 Feb 2021
Posts: 5

PostPosted: Wed Feb 17, 2021 8:16 am    Post subject: Reply with quote

You won't believe it, but it worked. I see before my eyes a site where non-cached conditions with cached content.
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Wed Feb 17, 2021 8:17 am    Post subject: Reply with quote

Parser should have crashed all the time on this construction. You just can't write code like this.
Back to top
View user's profile Send private message
MadGreen
Smarty Rookie


Joined: 15 Feb 2021
Posts: 5

PostPosted: Wed Feb 17, 2021 8:21 am    Post subject: Reply with quote

Should, but didn't crash before 3.1.18 Smile
How else to organize a non-cached if, inside of which the content should be cached?
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Wed Feb 17, 2021 5:16 pm    Post subject: Reply with quote

That's oxymoron.
Give me a real world use case where such construct is useful.
Back to top
View user's profile Send private message
MadGreen
Smarty Rookie


Joined: 15 Feb 2021
Posts: 5

PostPosted: Wed Feb 17, 2021 7:00 pm    Post subject: Reply with quote

The authorized user needs to show the content that is not available to the unauthorized user. How do I do this in a cached template?
The content is requested from the database and cached, on the page the difference is only in authorization.
Back to top
View user's profile Send private message
MadGreen
Smarty Rookie


Joined: 15 Feb 2021
Posts: 5

PostPosted: Fri Feb 19, 2021 7:22 am    Post subject: Reply with quote

here is a similar problem https://www.smarty.net/forums/viewtopic.php?p=75251
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Fri Feb 19, 2021 7:24 am    Post subject: Reply with quote

Use a plugin that calls back to Smarty to render cached content.
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 -> 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