Magento 2 Template – How to Overwrite Lib Template File

htmlknockoutjsmagento2overridestemplate

How can the HTML files from the library be overwritten?

I need to overwrite this template:

  • lib/web/mage/gallery/gallery.html

I have tried placing the file in my own theme in the below locations, I've cleared my cache between each file move.

  • app/design/frontend/**VENDOR**/**THEME**/web/mage/gallery/gallery.html
  • app/design/frontend/**VENDOR**/**THEME**/web/gallery/gallery.html
  • app/design/frontend/**VENDOR**/**THEME**/web/lib/mage/gallery/gallery.html
  • app/design/frontend/**VENDOR**/**THEME**/web/lib/gallery/gallery.html
  • app/design/frontend/**VENDOR**/**THEME**/mage/gallery/gallery.html
  • app/design/frontend/**VENDOR**/**THEME**/web/template/gallery/gallery.html

I've read through the dev docs and can't see anything mentioned in there either.

Best Answer

Correct Location

The correct location in this example is actually the first one I tried, I just didn't clear the directories required. So to overwrite lib templates they need duplicating in to the theme directory excluding the lib directory.

Correct location -app/design/frontend/**VENDOR**/**THEME**/web/mage/gallery/gallery.html

Clear pub/static and var/view_preprocessed

I actually placed the file in the correct location the first time, the main issue I had was that I wasn't clearing pub/static and var/view_preprocessed between file moves.

Related Topic