I have added below code to load custom template file from cms.

<p>{{block class="Vendor\Module\Block\Testblock" template="Vendor_Module::test_template.phtml"}}</p>

If template is loaded in xml file i can use cacheable="false" then page will no cached.

so how to add same functionality in cms?

Because i am trying to get logged in customer details. but this is not retrieving since page is cached i guess.

All i am looking to get customer details. Used below code and injected this class


return $this->customerSession->getCustomer();

Can anyone look into this and suggest me.

  • You can refer this for get logged in customer detail from session. webkul.com/blog/… Mar 21 '19 at 18:04
  • @PragnadeepPitroda, customer session is not working since it is cached, so pls help me in getting customer session else avoid page being cached Mar 22 '19 at 6:11

You can set in your default.xml layout file.

Path : app/code/VendorName/ModuleName/view/frontend/layout/default.xml

<referenceContainer name="content"> 
 <block name="test" cacheable="false"/> 

For debugging You can disable cache from magento admin panel ( Settings->Cache Management select all, next select Disable instead of Refresh and click Submit )

Or type this command in terminal: bin/magento cache:disable

But in your situation i think that clearing cache is enough:

bin/magento cache:clean

bin/magento cache:flush


If you want to make the complete page non-cacheable then you can try cacheable attribute in any block. Blocks can be set as non-cacheable by setting the cacheable attribute false in layout XML files. For example:

<block class="Block\Class" name="blockname" cacheable="false" />

Pages containing such blocks are not cached.

Reference : https://devdocs.magento.com/guides/v2.2/extension-dev-guide/cache/page-caching/public-content.html

  • this works if we used from file but my question is how to use in cms Mar 22 '19 at 6:12
  • @jafarpinjar - You have to extend the cms module and add the headers info on controller execute action based on page id. This is another way to make the specific cms page as non-cacheable.
    – Thamo
    Mar 22 '19 at 9:04

You can check the option of sections in magento 2. You can load the specific block elements via sections on fully cached page. Its something similar to your mini-cart feature on home page header. The home page was cached fully.


You can use cacheable="false" and it will working fine.

<p>{{block class="Vendor\Module\Block\Testblock" template="Vendor_Module::test_template.phtml" cacheable="false"}}</p>

Hope it help!


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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