Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recent {{ nocache }} tag improvements seem to ignore variable usages in if statements or usages within partials #9123

Closed
morhi opened this issue Dec 5, 2023 · 2 comments · Fixed by #9124

Comments

@morhi
Copy link
Contributor

morhi commented Dec 5, 2023

Bug description

This happened after #8956 was released. When using the {{ nocache }} tag, variables are only available inside the tag, if their value was directly used, but not, if they are only used within if statements. The also get ignored, when used (even when simply outputting the value) within a partial inside the nocache tag.

To me this seems like an unwanted breaking change. Do you think it is possible to fix this issue?

How to reproduce

  1. Create any template with the nocache tag:
{{ nocache }}
  {{ if show_me }}
    <span>hi there</span>
  {{ /if }}
{{ /nocache }}
  1. The if within the nocache tag will not trigger the variable to be stored for the nocache context. This would work though:
{{ nocache }}
  {{ show_me }}
  {{ if show_me }}
    <span>hi there</span>
  {{ /if }}
{{ /nocache }}

Of course, it would output the value of the variable, which I don't want.

Possible workaround: Using the {{ nocache select="show_me" }} syntax instead.

Logs

No response

Environment

Environment
Laravel Version: 10.34.2
PHP Version: 8.1.24

Statamic
Antlers: runtime
Static Caching: Disabled
Version: 4.38.0 PRO

Installation

Fresh statamic/statamic site via CLI

Antlers Parser

runtime (new)

Additional details

No response

@duncanmcclean
Copy link
Member

As a workaround, you can specify the variables you want to use with the select parameter:

{{ nocache select="variable_name|another|foo" }}
  <!-- And your code here -->
{{ /nocache }}

@morhi morhi changed the title Recent {{ nocache }} tag improvements seem to ignore variable usages in if statements Recent {{ nocache }} tag improvements seem to ignore variable usages in if statements or usages within partials Dec 5, 2023
@jasonvarga
Copy link
Member

jasonvarga commented Dec 5, 2023

I can't reproduce the condition thing. It even picks up the if.

Maybe there's another part to your issue that you didn't describe.

The partial though, yep.

Nevertheless, this behavior is being changed to opt-in in #9124, and you can opt-in like Duncan described.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants