0

I am trying to show or hide a block based on a cookie. The cookie is set on a form submission and whether the user sees the block depends on if they have the cookie set. I have it working but when Full Page Cache is enabled it ignores the cookie and just shows whatever is in the cache.

At it's most basic I have the following at the top of the block phtml:

if(!$allowedToView){
 return;
}
// else show the block content.

I don't want to use cacheable=false for obviously reasons.

I have considered using private content to "Hole punch" but I don't need to display personal content, just the block itself. Any suggestions on how best to achieve this?

Thanks.

asked Jan 13, 2022 at 15:18

1 Answer 1

0

I would suggest using something called HTTP context. It allows you to have multiple versions of the same page but still serve it via FPC. For example it’s used to show different prices to different customer groups who have catalog price rules.

Take a look here for how to achieve it 🙂 https://www.atwix.com/magento-2/cache-context-and-page-variations-in-magento-2/

answered Jan 13, 2022 at 20:25

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.