【问题标题】:How to add a custom product template in NopCommerce plugin如何在 NopCommerce 插件中添加自定义产品模板
【发布时间】:2021-08-18 11:04:36
【问题描述】:

我创建了一个插件,但它需要一个定制的产品模板,我无法让它工作。有人可以帮我理解我做错了什么吗?

到目前为止,我有:

  1. 转到https://example.com/Admin/Template/List并添加了新的产品模板 1a。将视图路径设置为“myCustomPlugin.Views.Product.ProductTemplateCustom.Simple”
  2. 转到https://example.com/Admin/Product/Edit/46 并使用新产品模板设置该产品
  3. 在我的插件代码中,我在以下位置创建了模板:myCustomPlugin\Views\Product\ProductTemplateCustom.Simple.cshtml
  4. 已加载产品页面

当我加载我得到的产品页面时:

InvalidOperationException:InvalidOperationException:未找到视图“ProductTemplateCustom.Simple”。搜索了以下位置: /Themes/DefaultClean/Views/Product/ProductTemplateCustom.Simple.cshtml /Themes/DefaultClean/Views/Shared/ProductTemplateCustom.Simple.cshtml /Views/Product/ProductTemplateCustom.Simple.cshtml /Views/Shared/ProductTemplateCustom .Simple.cshtml /Pages/Shared/ProductTemplateCustom.Simple.cshtml

  • 我检查了Nop.Web\Plugins\myCustomPlugin\Views\ProductProductTemplateCustom.Simple.cshtml 已被复制。

  • 我查看了RouteProvider.cs,期待需要将一些路由配置添加到我的插件中,但我什么也看不到

  • Their documentation 说我必须向Views\Product 添加一个新产品模板,所以我已经这样做了,但它存在于我的插件路径中,我无法弄清楚如何让 NopCommerce 在该位置查看

【问题讨论】:

    标签: nopcommerce


    【解决方案1】:

    听起来您正在寻找的是IViewLocationExpander。简单来说,此界面允许您添加自定义视图位置,因此您可以覆盖插件中的默认视图。

    您可以在 Presentation\Nop.Web.Framework\Themes\ThemeableViewLocationExpander.cs 中找到一个实现

    直接的方法是提供视图的完整路径。不过,我更喜欢使用 ViewLocationExpander,感觉更有序、更整洁。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多