This project is read-only.

How can I get resource manager to register css and javascript in html helper extension ?

Topics: Administration, Customizing Orchard, General, Writing modules, Writing themes
Jul 20, 2011 at 3:44 AM


I create custom html helper to use in widget and I would like to register css and javascript in the helper because when I use this helper I have not to call Script.Require or Style.Require all the time that I need but I have no idea how to get resource manager to register css and javascript because I cannot call Script.Require or Style.Require.


public static class CustomExtension
    public static MvcHtmlString Custom(this HtmlHelper helper)
        /*TODO: _resourceManager.Require("script", "jQuery");
                _resourceManager.Include("script", "~/Modules/Custom/Scripts/custom.js", null); */
        return MvcHtmlString.Create("Custom Helper");




Jul 20, 2011 at 5:11 AM

Why extend HtmlHelper? You could extend ScriptRegister instead and get Include and Require from it.

Jul 20, 2011 at 6:40 AM

bertrandleroy, Thank you for your suggestion and I found the way to get Script and Style as code below.

var orchardViewPage = helper.ViewDataContainer as IOrchardViewPage;

And I would like to know how can I register startup script for helper to initialize script.




Jul 26, 2011 at 1:48 AM
@using(Script.Foot()) {
<script type="text/javascript">

// Write your startup script here