I want to add a block in header which will not be cached. The block needs to be added to default.xml. I can't set cacheble="false"to the block as it will make all pages non-cacheble ( Reference ). What is the best way to achieve this ?

1 Answer 1


You can add the block, but you can not work with visitor-specific elements - such as a customer's name or cart contents - in pure PHP.

Instead, you need to handle the data using Knockout.js

Here is the relevant documentation on this: https://developer.adobe.com/commerce/php/development/cache/page/private-content/

  • I have an input field on the block where user can add their zipcode, and after pressing the submit, I am adding the zipcode in a cookie using Js. I know that to update private content, you need to have a sections.xml where you put a controller path , upon hitting which the content refreshes. In my case, I am seeing the old zipcode even after I have set the cookie, and refreshed the page. It updated only after I clean the cache. Should I add cms/index/index in sections ? Mar 15 at 9:11
  • It's hard to say without seeing the code, but I guess that you're reading the cookie with PHP? That's wrong; you must read it with JS. If that doesn't work, check if you controller path is correct in sections.xml, and maybe try to update all sections instead of only your own; but again, hard to say without the code. Mar 17 at 19:17
  • @AniruddhaRay if you're setting the cookie via JS, maybe it's wise to populate the field via using JS as well. I mean, keep the field empty by default and once the page is loaded, populate the value via JS. Mar 24 at 9:44

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.