Calling Script.Require in Shape view returned from IResultFilter not working in Orchard CMS?

与世无争的帅哥 提交于 2019-12-11 17:40:11

问题


I'm currently writing my own module that needs some scripts to be loaded on all pages, both on the front-end and the dashboard, where the user is authorized to edit content. I've written an implementation of the IResultFilter that adds a shape to the 'tail' zone in the site's theme.

The shape is added to the page correctly and all is OK except for one thing. In the same shape I'm also trying to call Script.Require on a few scripts that I've added to the ResourceManifest, but they're not being loaded in to the page.

@{
    Script.Require("OrchardTinyMce");
    Script.Require("jQueryColorBox");
}

If I place this same code in a view that's not rendered using my IResultsFilter implementation then they are added to the page. I'd rather keep this bit of code in it's current view though as two alternates further down the line which require the same scripts and I don't really want to duplicate it.

Does anyone have any ideas how I get the scripts to register? Thanks in advance for you help.


回答1:


I'm not sure why that isn't working in your view, but you could just use the resource manager to add those scripts from your filter:

_resourceManager.Require("script", "OrchardTinyMce").AtFoot();

Inject the resource manager as per usual:

private readonly IResourceManager _resourceManager;
public MyFilter(IResourceManager resourceManager) {
  _resourceManager = resourceManager;
}



回答2:


I've worked out how to do this. I've just injected IResourceManager into my HtmlFilter and then added the scripts as follows:

_resourceManager.Require("OrchardTinyMce");
_resourceManager.Require("jQueryColorBox");



回答3:


If you want that other user or you can simple override this scripts (use lightBox insted colorBox). You can add your shape to Content Zone (but this shape shouldn't have output html).

Services.WorkContext.Layout.Content.Add(YourShape, ":after");

It works from IResultsFilter



来源:https://stackoverflow.com/questions/27019727/calling-script-require-in-shape-view-returned-from-iresultfilter-not-working-in

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!