I've been programming Magento 1 for many years but I'm just getting into Magento 2 and I am a little confused about the theme folder structure. From what I have found there's really no concept of theme-specific template files. Templates are inside modules now. To overwrite a parent theme's template, simply put your own template file in the same folder as the parent theme's file.
For example, let's say I have a theme called "Mytheme/Default" and I want to change the
footer.phtml template for my theme. The default one lives in
[site_root]\vendor\magento\module-theme\view\frontend\templates\html\footer.phtml. This tells me it's in the Magento Theme extension, so I need to put my override template in
However, the part that isn't clear is where I'm supposed to put template files that are entirely custom but not related to any module at all. I have since learned that these should probably reside under the
Magento_Theme extension, howerver, while playing around and trying things I discovered that I can create a
templates subdirectory in my theme folder (outside of any Module folders) and it actually works. I can't find anything online about this so I'm wondering if it's a side effect of how Magento looks for template files or if this is actually a supported method for creating custom templates that aren't part of an extension.
I also read that if the template file you're trying to use lives in the same Module as the XML file providing the instructions you can avoid the
Vendor_Module:: prefix on the template declaration in the XML. For instance, if I create a new block inside the body of a page and I instantiate this using a
default.xml file inside my theme under the
Magento_Theme module directory, and if I put my template somewhere in the same
Magento_Theme module directory, I should be able to use
template="path/to/template.phtml in my layout XML instead of the longer version,
template="Magento_Theme::path/to/template.phtml". This, however, does not work in my experience and I always need the
If I put my custom template in the (perhaps unsupported)
templates subdirectory inside my theme's root folder (i.e.
...app/design/frontend/Mytheme/Default/templates) I don't need any module prefix and it actually works.
Is this supported or is it just by happenstance that it's working?