I want to show a popup phtml based on wether a cookie has been set or not in my block class.
The logic is roughly:
class Popup extends \Magento\Framework\View\Element\Template
{
public function shouldShowPopup()
{
if ($this->cookie->get()) {
return false;
}
return true;
}
}
Then in the phtml:
if ($block->shouldShowPopup() ) {
echo 'HTML Content here';
}
My issue is that shouldShowPopup() seems to be caching, so I'm getting inconsistent results.
Is there a way to mark this so as not to be cached? I have tried
<argument name="cache_lifetime" xsi:type="number">0</argument>
which doesn't have any effect and also:
<block class="Block\Class" name="blockname" cacheable="false" />
which removed the cache from the whole page.
If (like I have read elsewhere) this is not possible, should this logic be implemented somewhere more suitable outside of the block class?