简体   繁体   English

如何将自定义模板(phtml)文件放置在本地模块目录中,而不是默认模板目录中

[英]How to place custom template (phtml) file in local module direcotry instead of default template directory

I am creating a new module for my Magento project where I have a few template files which get appended to >catalog_product_view catalog_category_default checkout_cart_index and few other pages. 我正在为我的Magento项目创建一个新模块,其中有一些模板文件,这些文件被追加到> catalog_product_view catalog_category_default checkout_cart_index和其他几页。 Currently, I have placed my module configuration file in >design/fontend/base/default/layout/modulename_subfolder.xml and template file is placed at >design/frontend/base/default/template/modulename/subfolder/my_product_view.phtml 目前,我已将模块配置文件放置在> design / fontend / base / default / layout / modulename_subfolder.xml中,并且模板文件放置在> design / frontend / base / default / template / modulename / subfolder / my_product_view.phtml中

I want to move this XML and phtml files to local/modulename/subfolder 我想将此XML和phtml文件移动到local / modulename / subfolder

I have tried creating the same folder structure in my module folder but it didn't work 我尝试在模块文件夹中创建相同的文件夹结构,但是没有用

design/fontend/base/default/layout/modulename_subfolder.xml 设计/字体/基本/默认/布局/modulename_subfolder.xml


<layout version="0.1.0">
  <catalog_product_view>
    <reference name="content">
      <block type="core/template" name="modulename_subfolder_product_view_block" template="modulename/subfolder/my_catalog_product_view.phtml" />
    </reference>
  </catalog_product_view>
</layout>

您必须在htdocs/app/design/frontend/base/default/template/yourcompany/module中执行指向该模块相同目录的符号链接。

You can do that, but it is not correct. 您可以这样做,但这是不正确的。 If you have hard times to find files in your magento structure you need to practice more, and you will see that it is not that hard as it seems. 如果您很难在magento结构中查找文件,则需要进行更多练习,您会发现它并不像看上去那样困难。

Whatever, put your files in your Magento's module (in any subfolder), then go to the correct place where they should be (like: frontend/design/.../file.phtml) and create a file that includes your module's files path. 无论如何,将文件放在Magento的模块中(在任何子文件夹中),然后转到应该放置的正确位置(例如:frontend / design /.../ file.phtml),并创建一个包含模块文件路径的文件。

For template files, just open the php tags and include it; 对于模板文件,只需打开php标签并将其包括在内; like this reference shows https://www.php.net/manual/en/function.include.php 像这样的参考显示https://www.php.net/manual/en/function.include.php

for xml is almost the same; 对于xml几乎相同; follow this answer for XML Can we import XML file into another XML file? 遵循XML的此答案, 可以将XML文件导入另一个XML文件吗? .

I suggest to not do that, but instead put your files where they belong. 我建议不要这样做,而是将文件放在它们所属的位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM