Skip to content
This repository was archived by the owner on Dec 14, 2018. It is now read-only.
This repository was archived by the owner on Dec 14, 2018. It is now read-only.

Add HTML helper methods for rendering globbed stylesheet & JavaScript references with fallback #2024

@DamianEdwards

Description

@DamianEdwards

Add methods to IHtmlHelper that support rendering HTML for stylesheet links and script blocks with support for globbed file paths and fallbacks. Basically the equivalent of the features of the link and script tag helpers.

Example

@section head {
    @if (HostingEnvironment.IsDevelopment()) {
        @Html.Stylesheet(include: "lib/**/*.css", exclude: "css/**/*.css");
        @Html.Stylesheet(include: "css/**/*.css", exclude: "lib/**/*.css");
    }
    else if (HostingEnvironment.IsProduction()) {
        @Html.Stylesheet(
            href: "//mycdn.com/bootstrap/2.1.0.min.css",
            fallbackHrefInclude: "lib/bootstrap/css/*.min.css",
            fallbackTestClass: "hidden", 
            fallbackTestProperty: "visibility",
            fallbackTestValue: "hidden");
        @Html.Stylesheet(href: "css/site.min.css", fallbackHrefInclude: "css/**/*.min.css");
    }
}

@section scripts {
    @if (HostingEnvironment.IsDevelopment()) {
        @Html.Script(src: "lib/jquery/jquery.js");
        @Html.Script(src: "lib/jquery-ui/jquery-ui.js");
        @Html.Script(include: "js/**/*.js", exclude: "lib/**/*.js");
    }
    else if (HostingEnvironment.IsProduction()) {
        @Html.Script(
            src: "//mycdn/jquery/2.1.2.min.js",
            fallbackSrc: "lib/jquery/jquery.min.js",
            fallbackTest: "window.jQuery"
        );
        @Html.Script(
            src: "//mycdn/jquery-ui/1.12.0.min.js",
            fallbackSrc: "lib/jquery-ui/jquery-ui.min.js",
            fallbackTest: "window.jQuery && window.jQuery.ui"
        );
        @Html.Script(src: "js/site.min.js" fallbackSrcInclude: "js/**/*.min.js");
    }
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions