View previous topic :: View next topic |
Author |
Message |
MadGreen Smarty Rookie
Joined: 15 Feb 2021 Posts: 5
|
Posted: Mon Feb 15, 2021 12:25 pm Post subject: Smarty nocache condition |
|
|
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 |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Wed Feb 17, 2021 8:11 am Post subject: |
|
|
There's nothing to resolve, it was not working before, you just get a notification about it now. |
|
Back to top |
|
MadGreen Smarty Rookie
Joined: 15 Feb 2021 Posts: 5
|
Posted: Wed Feb 17, 2021 8:16 am Post subject: |
|
|
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 |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Wed Feb 17, 2021 8:17 am Post subject: |
|
|
Parser should have crashed all the time on this construction. You just can't write code like this. |
|
Back to top |
|
MadGreen Smarty Rookie
Joined: 15 Feb 2021 Posts: 5
|
Posted: Wed Feb 17, 2021 8:21 am Post subject: |
|
|
Should, but didn't crash before 3.1.18
How else to organize a non-cached if, inside of which the content should be cached? |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Wed Feb 17, 2021 5:16 pm Post subject: |
|
|
That's oxymoron.
Give me a real world use case where such construct is useful. |
|
Back to top |
|
MadGreen Smarty Rookie
Joined: 15 Feb 2021 Posts: 5
|
Posted: Wed Feb 17, 2021 7:00 pm Post subject: |
|
|
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 |
|
MadGreen Smarty Rookie
Joined: 15 Feb 2021 Posts: 5
|
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Fri Feb 19, 2021 7:24 am Post subject: |
|
|
Use a plugin that calls back to Smarty to render cached content. |
|
Back to top |
|
|