Search code examples
cachingtypo3view-helperstx-gridelements

Typo3: Disable caching for viewhelper inside gridelements fluid template


I have an inherited typo3 website (running 10.4.31 now) that must have been created in 2016 or so, and it contains a custom ViewHelper that has some time-based logic (you can set a countdown and once it's elapsed, something is supposed to happen). The problem is that it only works if you're logged in, in dev environments or when you have the cache disabled globally.

the setup is something like this:

TypoScript:

tt_content.gridelements_pi1.20.10.setup {
    37 < lib.gridelements.defaultGridSetup
    37 {
        cObject = FLUIDTEMPLATE
        cObject {
            file = EXT:myext/Resources/Private/Templates/gridelements/ce/countdown.html
        }
    }
}

Template

<div class="countdown-container">
    {namespace content=My\Ext\ViewHelpers}
    <content:Countdown time="{data.flexform_date}" image="{data.flexform_image}" />
</div>

and then the aforementioned custom Viewhelper.

The question is: Is there any way to tell typo3 to execute the ViewHelper's PHP code every time instead of caching? I have googled a lot, but none of the solutions I've found work. Things I have tried include:

  • adding <f:cache.disable /> to the HTML template: no effect
  • throwing StopCompilingException from the ViewHelper's compile method: no effect (but I can see that the exception gets thrown and caught)
  • adding COA_INT or USER_INT to the typoscript: no effect (I can see them in the object browser, but honestly I don't know if I put them in the right place)

Solution

  • You can disable the cache for this specific Gridelement by using a COA_INT container as surrounding cObject:

    tt_content.gridelements_pi1.20.10.setup {
      37 < lib.gridelements.defaultGridSetup
      37 {
        cObject = COA_INT
        cObject {
          10 = FLUIDTEMPLATE
          10.file = EXT:myext/Resources/Private/Templates/gridelements/ce/countdown.html
        }
      }
    }